Module: Radio5::Client::Users

Includes:
Radio5::Constants
Included in:
Radio5::Client
Defined in:
lib/radio5/client/users.rb

Defined Under Namespace

Modules: Parser

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

Instance Method Summary collapse

Instance Method Details

#user(id) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/radio5/client/users.rb', line 8

def user(id)
  validate_user_id!(id)

  _, json = api.get("/contributor/#{id}")

  Parser.(json)
rescue Api::UserNotFound
  nil
end

#user_follow_counts(id) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/radio5/client/users.rb', line 37

def user_follow_counts(id)
  validate_user_id!(id)

  _, json = api.get("/follow/count/#{id}")

  {
    followings: json.fetch(:following),
    followers: json.fetch(:followers)
  }
end

#user_followers(id, size: MAX_PAGE_SIZE, page: 1) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/radio5/client/users.rb', line 48

def user_followers(id, size: MAX_PAGE_SIZE, page: 1)
  validate_user_id!(id)
  validate_page_size!(size)
  validate_page_number!(page)

  _, json = api.get("/follow/list/follower/#{id}", query_params: {size: size, page: page})

  json.map do |user|
    Parser.(user)
  end
end

#user_followings(id, size: MAX_PAGE_SIZE, page: 1) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/radio5/client/users.rb', line 60

def user_followings(id, size: MAX_PAGE_SIZE, page: 1)
  validate_user_id!(id)
  validate_page_size!(size)
  validate_page_number!(page)

  _, json = api.get("/follow/list/following/#{id}", query_params: {size: size, page: page})

  json.map do |user|
    Parser.(user)
  end
end

#user_liked_tracksObject

Raises:

  • (NotImplementedError)


72
73
74
# File 'lib/radio5/client/users.rb', line 72

def user_liked_tracks
  raise NotImplementedError, "depends on auth"
end

#user_tracks(id, status: :on_air, size: MAX_PAGE_SIZE, page: 1) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/radio5/client/users.rb', line 18

def user_tracks(id, status: :on_air, size: MAX_PAGE_SIZE, page: 1)
  validate_user_id!(id)
  validate_user_track_status!(status)
  validate_page_size!(size)
  validate_page_number!(page)

  query_params = {
    status: stringify_user_track_status(status),
    size: size,
    page: page
  }

  _, json = api.get("/contributor/uploaded/#{id}", query_params: query_params)

  json.map do |track|
    Parser.user_track_info(track)
  end
end