Пример #1
0
        public MediaImage(JsonElement image)
        {
            if (image.IsNull())
            {
                return;
            }

            Width     = image.GetInt("w");
            Height    = image.GetInt("h");
            ImageType = image.GetString("image_type");
        }
Пример #2
0
        public MediaProcessingInfo(JsonElement info)
        {
            if (info.IsNull())
            {
                return;
            }

            State             = info.GetString("state");
            CheckAfterSeconds = info.GetInt("check_after_secs");
            ProgressPercent   = info.GetInt("progress_percent");
            info.TryGetProperty("error", out JsonElement errorValue);
            Error = new MediaError(errorValue);
        }
Пример #3
0
        internal Location(JsonElement trendLocation)
        {
            if (trendLocation.TryGetProperty("placeType", out JsonElement placeType))
            {
                PlaceTypeName     = placeType.GetString("name");
                PlaceTypeNameCode = placeType.GetInt("code");
            }

            Country     = trendLocation.GetString("country");
            Name        = trendLocation.GetString("name");
            CountryCode = trendLocation.GetString("countryCode");
            ParentID    = trendLocation.GetInt("parentid").ToString(CultureInfo.InvariantCulture);
            Url         = trendLocation.GetString("url");
            WoeID       = trendLocation.GetInt("woeid");
        }
Пример #4
0
        public Media(JsonElement media)
        {
            if (media.IsNull())
            {
                return;
            }

            media.TryGetProperty("image", out JsonElement imageValue);
            Image   = new MediaImage(imageValue);
            MediaID = (media.GetString("media_id_string") ?? "0").GetULong();
            Size    = media.GetInt("size");
            media.TryGetProperty("video", out JsonElement video);
            VideoType           = video.GetString("video_type");
            ExpiresAfterSeconds = media.GetInt("expires_after_secs");
            media.TryGetProperty("processing_info", out JsonElement processingInfoValue);
            ProcessingInfo = new MediaProcessingInfo(processingInfoValue);
        }
Пример #5
0
 public SavedSearch(JsonElement searchJson)
 {
     Query      = searchJson.GetString("query");
     Name       = searchJson.GetString("name");
     Position   = searchJson.GetInt("position");
     IDResponse = searchJson.GetUlong("id");
     CreatedAt  = searchJson.GetString("created_at")?.GetDate(DateTime.MaxValue);
 }
Пример #6
0
 public List(JsonElement element) : this()
 {
     Name        = element.GetString("name");
     FullName    = element.GetString("full_name");
     MemberCount = element.GetInt("member_count");
     Description = element.GetString("description");
     Mode        = element.GetString("mode");
     Uri         = element.GetString("uri");
     Users       = new List <User> {
         new User(element.GetProperty("user"))
     };
     ListIDResponse  = element.GetUlong("id");
     SubscriberCount = element.GetInt("subscriber_count");
     CreatedAt       = element.GetString("created_at")?.GetDate(DateTime.MaxValue);
     Following       = element.GetBool("following");
     SlugResponse    = element.GetString("slug");
 }
Пример #7
0
        public EmbeddedStatus(JsonElement embeddedStatusJson)
        {
            Html         = embeddedStatusJson.GetString("html");
            AuthorName   = embeddedStatusJson.GetString("author_name");
            AuthorUrl    = embeddedStatusJson.GetString("author_url");
            ProviderName = embeddedStatusJson.GetString("provider_name");
            ProviderUrl  = embeddedStatusJson.GetString("provider_url");
            Url          = embeddedStatusJson.GetString("url");
            Version      = embeddedStatusJson.GetString("version");
            Type         = embeddedStatusJson.GetString("type");
            Height       = embeddedStatusJson.GetInt("height");
            Width        = embeddedStatusJson.GetInt("width");
            string?cacheAgeStr = embeddedStatusJson.GetString("cache_age");

            if (!string.IsNullOrWhiteSpace(cacheAgeStr))
            {
                CacheAge = ulong.Parse(cacheAgeStr);
            }
        }
Пример #8
0
 public SearchMetaData(JsonElement metaData)
 {
     CompletedIn = metaData.GetDecimal("completed_in");
     NextResults = metaData.GetString("next_results");
     Query       = metaData.GetString("query");
     RefreshUrl  = metaData.GetString("refresh_url");
     Count       = metaData.GetInt("count");
     MaxID       = (metaData.GetString("max_id_str") ?? string.Empty).GetULong();
     SinceID     = (metaData.GetString("since_id_str") ?? string.Empty).GetULong();
 }
Пример #9
0
        public MediaError(JsonElement error)
        {
            if (error.IsNull())
            {
                return;
            }

            Code    = error.GetInt("code");
            Name    = error.GetString("name");
            Message = error.GetString("message");
        }
Пример #10
0
 Help HandleHelpConfiguration(JsonElement helpJson)
 {
     if (helpJson.TryGetProperty("photo_sizes", out JsonElement photoSizeDict))
     {
         return new Help
                {
                    Type          = HelpType.Configuration,
                    Configuration = new Configuration
                    {
                        CharactersReservedPerMedia = helpJson.GetInt("characters_reserved_per_media"),
                        PhotoSizes =
                            (from key in photoSizeDict.EnumerateObject()
                             let photoSize = photoSizeDict.GetProperty(key.Name)
                                             select new PhotoSize
                 {
                     Type = key.Name,
                     Height = photoSize.GetInt("h"),
                     Width = photoSize.GetInt("w"),
                     Resize = photoSize.GetString("resize")
                 })
                            .ToList(),
                        ShortUrlLength   = helpJson.GetInt("short_url_length"),
                        PhotoSizeLimit   = helpJson.GetInt("photo_size_limit"),
                        NonUserNamePaths =
                            (from path in helpJson.GetProperty("non_username_paths").EnumerateArray()
                             select path.ToString())
                            .ToList(),
                        MaxMediaPerUpload   = helpJson.GetInt("max_media_per_upload"),
                        ShortUrlLengthHttps = helpJson.GetInt("short_url_length_https")
                    }
                }
     }
     ;
     else
     {
         return(new Help());
     }
 }
Пример #11
0
        public Category(JsonElement catJson)
        {
            Size = catJson.GetInt("size");
            Name = catJson.GetString("name");
            Slug = catJson.GetString("slug");

            catJson.TryGetProperty("users", out JsonElement users);
            if (!users.IsNull())
            {
                Users =
                    (from user in users.EnumerateArray()
                     select new User(user))
                    .ToList();
            }
        }
Пример #12
0
        public User(JsonElement user)
        {
            if (user.IsNull())
            {
                return;
            }

            BannerSizes        = new List <BannerSize>();
            Categories         = new List <Category>();
            UserIDResponse     = user.GetUlong("id").ToString(CultureInfo.InvariantCulture);
            ScreenNameResponse = user.GetString("screen_name");
            Name                 = user.GetString("name");
            Location             = user.GetString("location");
            Description          = user.GetString("description");
            ProfileImageUrl      = user.GetString("profile_image_url");
            ProfileImageUrlHttps = user.GetString("profile_image_url_https");
            Url = user.GetString("url");
            user.TryGetProperty("entities", out JsonElement entitiesValue);
            Entities  = new UserEntities(entitiesValue);
            Protected = user.GetBool("protected");
            ProfileUseBackgroundImage = user.GetBool("profile_use_background_image");
            IsTranslator              = user.GetBool("is_translator");
            FollowersCount            = user.GetInt("followers_count");
            DefaultProfile            = user.GetBool("default_profile");
            ProfileBackgroundColor    = user.GetString("profile_background_color");
            LangResponse              = user.GetString("lang");
            ProfileTextColor          = user.GetString("profile_text_color");
            ProfileLinkColor          = user.GetString("profile_link_color");
            ProfileSidebarFillColor   = user.GetString("profile_sidebar_fill_color");
            ProfileSidebarBorderColor = user.GetString("profile_sidebar_border_color");
            FriendsCount              = user.GetInt("friends_count");
            DefaultProfileImage       = user.GetBool("default_profile_image");
            CreatedAt                      = (user.GetString("created_at") ?? string.Empty).GetDate(DateTime.MinValue);
            FavoritesCount                 = user.GetInt("favourites_count");
            UtcOffset                      = user.GetInt("utc_offset");
            TimeZone                       = user.GetString("time_zone");
            ProfileBackgroundImageUrl      = user.GetString("profile_background_image_url");
            ProfileBackgroundImageUrlHttps = user.GetString("profile_background_image_url_https");
            ProfileBackgroundTile          = user.GetBool("profile_background_tile");
            ProfileBannerUrl               = user.GetString("profile_banner_url");
            StatusesCount                  = user.GetInt("statuses_count");
            Notifications                  = user.GetBool("notifications");
            GeoEnabled                     = user.GetBool("geo_enabled");
            Verified                       = user.GetBool("verified");
            ContributorsEnabled            = user.GetBool("contributors_enabled");
            Following                      = user.GetBool("following");
            ShowAllInlineMedia             = user.GetBool("show_all_inline_media");
            ListedCount                    = user.GetInt("listed_count");
            FollowRequestSent              = user.GetBool("follow_request_sent");
            user.TryGetProperty("status", out JsonElement statusElement);
            Status         = new Status(statusElement);
            CursorMovement = new Cursors(user);
            Email          = user.GetString("email");
        }
Пример #13
0
        public VideoInfo(JsonElement videoInfo)
        {
            if (videoInfo.IsNull())
            {
                return;
            }

            videoInfo.TryGetProperty("aspect_ratio", out JsonElement aspectRatio);
            AspectRatio = new AspectRatio(aspectRatio);
            Duration    = videoInfo.GetInt("duration_millis");

            if (videoInfo.TryGetProperty("variants", out JsonElement variants))
            {
                Variants =
                    (from variant in variants.EnumerateArray()
                     select new Variant(variant))
                    .ToList();
            }
        }
Пример #14
0
 internal SleepTime(JsonElement sleepTime)
 {
     StartHour = sleepTime.GetInt("start_time");
     EndHour   = sleepTime.GetInt("end_time");
     Enabled   = sleepTime.GetBool("enabled");
 }
Пример #15
0
        public Status(JsonElement status)
        {
            if (status.IsNull())
            {
                return;
            }

            status.TryGetProperty("retweeted_status", out JsonElement retweetedStatus);
            RetweetedStatus     = new Status(retweetedStatus);
            Retweeted           = !retweetedStatus.IsNull();
            Source              = status.GetString("source");
            InReplyToScreenName = status.GetString("in_reply_to_screen_name");
            PossiblySensitive   = status.GetBool("possibly_sensitive");
            IsQuotedStatus      = status.GetBool("is_quote_status");
            QuotedStatusID      = status.GetUlong("quoted_status_id");
            status.TryGetProperty("quoted_status", out JsonElement quotedStatusValue);
            QuotedStatus = new Status(quotedStatusValue);
            status.TryGetProperty("contributors", out JsonElement contributors);
            Contributors =
                contributors.IsNull() ?
                new List <Contributor>() :
                (from contributor in contributors.EnumerateArray()
                 select new Contributor(contributor))
                .ToList();
            status.TryGetProperty("coordinates", out JsonElement coords);
            if (!coords.IsNull())
            {
                coords.TryGetProperty("coordinates", out JsonElement coordsValue);
                Coordinates = new Coordinate(coordsValue);
            }
            else
            {
                Coordinates = new Coordinate();
            }
            status.TryGetProperty("place", out JsonElement placeValue);
            Place             = new Place(placeValue);
            RetweetCount      = status.GetInt("retweet_count");
            StatusID          = status.GetUlong("id");
            FavoriteCount     = status.GetInt("favorite_count");
            Favorited         = status.GetBool("favorited");
            InReplyToStatusID = status.GetUlong("in_reply_to_status_id");
            CreatedAt         = status.GetDate("created_at", DateTime.MaxValue);
            InReplyToUserID   = status.GetUlong("in_reply_to_user_id");
            Truncated         = status.GetBool("truncated");
            status.TryGetProperty("display_text_range", out JsonElement displayTextRange);
            if (!displayTextRange.IsNull())
            {
                JsonElement[] displayTextIndices = displayTextRange.EnumerateArray().ToArray();
                DisplayTextRange = new List <int> {
                    displayTextIndices[0].GetInt32(), displayTextIndices[1].GetInt32()
                };
            }
            TweetMode tweetMode;

            Enum.TryParse(value: status.GetString("tweet_mode"), ignoreCase: true, result: out tweetMode);
            TweetMode = tweetMode;
            Text      = status.GetString("text");
            FullText  = status.GetString("full_text");
            status.TryGetProperty("extended_tweet", out JsonElement extendedTweetValue);
            ExtendedTweet = new Status(extendedTweetValue);
            status.TryGetProperty("annotation", out JsonElement annotationValue);
            Annotation = new Annotation(annotationValue);
            status.TryGetProperty("entities", out JsonElement entitiesValue);
            Entities = new Entities(entitiesValue);
            status.TryGetProperty("extended_entities", out JsonElement extendedEntitiesValue);
            ExtendedEntities = new Entities(extendedEntitiesValue);
            status.TryGetProperty("current_user_retweet", out JsonElement currentUserRetweet);
            if (!currentUserRetweet.IsNull())
            {
                CurrentUserRetweet = currentUserRetweet.GetProperty("id").GetUInt64();
            }
            // TODO: We need a good example of a scope so we can write a test.
            //JsonElement scopes = status.GetProperty("scopes");
            //Scopes =
            //    scopes.IsNull() ? new Dictionary<string, string>() :
            //    (from key in (scopes as IDictionary<string, JsonData>).Keys as List<string>
            //     select new
            //     {
            //         Key = key,
            //         Value = scopes[key].ToString()
            //     })
            //    .ToDictionary(
            //        key => key.Key,
            //        val => val.Value);
            WithheldCopyright = status.GetBool("withheld_copyright");
            status.TryGetProperty("withheld_in_countries", out JsonElement withheldCountries);
            if (withheldCountries.IsNull())
            {
                WithheldInCountries = new List <string>();
            }
            else
            {
                WithheldInCountries =
                    (from country in withheldCountries.EnumerateArray()
                     select country.GetString())
                    .ToList();
            }
            WithheldScope = status.GetString("withheld_scope");
            status.TryGetProperty("metadata", out JsonElement metadataValue);
            MetaData = new StatusMetaData(metadataValue);
            Lang     = status.GetString("lang");
            FilterLevel filterLevel;

            Enum.TryParse(value: status.GetString("filter_level"), ignoreCase: true, result: out filterLevel);
            FilterLevel = filterLevel;
            status.TryGetProperty("user", out JsonElement userValue);
            User  = new User(userValue);
            Users = new List <ulong>();
        }
Пример #16
0
 public Variant(JsonElement variant)
 {
     BitRate     = variant.GetInt("bitrate");
     ContentType = variant.GetString("content_type");
     Url         = variant.GetString("url");
 }
Пример #17
0
 internal TZInfo(JsonElement timeZone)
 {
     Name       = timeZone.GetString("name");
     TzInfoName = timeZone.GetString("tzinfo_name");
     UtcOffset  = timeZone.GetInt("utc_offset");
 }