Module: Radio5::Client::Users::Parser

Extended by:
Utils
Defined in:
lib/radio5/client/users.rb

Constant Summary

Constants included from Radio5::Constants

Radio5::Constants::ASSET_HOST, Radio5::Constants::DECADES, Radio5::Constants::IMAGE_SIZES, Radio5::Constants::MAX_PAGE_SIZE, Radio5::Constants::MOODS, Radio5::Constants::MOODS_MAPPING, Radio5::Constants::USER_TRACK_STATUSES, Radio5::Constants::USER_TRACK_STATUSES_MAPPING

Class Method Summary collapse

Methods included from Utils

create_asset_url, normalize_string, parse_asset_url, parse_image_urls, parse_json, parse_time_string, parse_unix_timestamp, stringify_moods, stringify_user_track_status, symbolize_mood, symbolize_user_track_status

Class Method Details

.follower_user_info(user) ⇒ Object Also known as: following_user_info



121
122
123
124
125
126
127
128
129
130
# File 'lib/radio5/client/users.rb', line 121

def self.(user)
  {
    id:         user.fetch(:_id),
    name:       normalize_string(user.fetch(:pseudonym)),
    country:    user[:country],
    rank:       user.fetch(:ranking),
    image_url:  parse_image_urls(user[:image], entity: :user),
    created_at: parse_time_string(user.fetch(:created))
  }
end

.normalize_year(time) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/radio5/client/users.rb', line 135

def self.normalize_year(time)
  if time.month == 12
    time.year + 1
  else
    time.year
  end
end

.user_info(json) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/radio5/client/users.rb', line 79

def self.(json)
  birthday = if json[:birthday]
    time = parse_time_string(json[:birthday])
    year_normalized = normalize_year(time)

    {
      time: time,
      year_normalized: year_normalized
    }
  end

  {
    id:         json.fetch(:_id),
    uuid:       json.fetch(:uuid),
    name:       normalize_string(json.fetch(:pseudonym)),
    info:       normalize_string(json[:info]),
    country:    json[:country],
    rank:       json.fetch(:ranking),
    image_url:  parse_image_urls(json[:image], entity: :user),
    birthday:   birthday,
    created_at: parse_time_string(json.fetch(:created))
  }
end

.user_track_info(track) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/radio5/client/users.rb', line 103

def self.user_track_info(track)
  cover_node = track[:image] || track[:cover]
  cover_url = parse_image_urls(cover_node, entity: :track)

  {
    id:          track.fetch(:_id),
    uuid:        track.fetch(:uuid),
    artist:      normalize_string(track.fetch(:artist)),
    title:       normalize_string(track.fetch(:title)),
    year:        normalize_string(track.fetch(:year)),
    cover_url:   cover_url,
    decade:      track.fetch(:decade),
    country:     track.fetch(:country),
    like_count:  track.fetch(:likes),
    status:      symbolize_user_track_status(track[:status])
  }
end