Class: Spacer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/spacer/client.rb

Constant Summary collapse

SERVER =
'api.msappspace.com'
VERSION =
'v1'
FORMAT =
:json
LOG_LEVEL =
Logger::INFO

Instance Method Summary collapse

Constructor Details

#initialize(api_key, secret_key, logger = nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
18
# File 'lib/spacer/client.rb', line 9

def initialize(api_key, secret_key, logger=nil)
  @auth = Authentication.new(api_key, secret_key)
  
  if logger
    @log = logger
  else
    @log = Logger.new(STDOUT)
    @log.level = LOG_LEVEL
  end
end

Instance Method Details

#album(user_id, album_id) ⇒ Object



50
51
52
53
# File 'lib/spacer/client.rb', line 50

def album(user_id, album_id)
  response = do_request "users/#{user_id}/albums/#{album_id}"
  @album = Album.from_hash(response)
end

#albums(user_id) ⇒ Object



43
44
45
46
47
48
# File 'lib/spacer/client.rb', line 43

def albums(user_id)
  response = do_request "users/#{user_id}/albums"
  @albums = response['albums'].map do |album|
    Album.from_hash(album)
  end
end

#details(user_id) ⇒ Object



74
75
76
77
# File 'lib/spacer/client.rb', line 74

def details(user_id)
  response = do_request "users/#{user_id}/details"
  @details = Details.from_hash(response)
end

#friends(user_id, page = nil, page_size = nil, list = nil) ⇒ Object

Optional attributes:

page: (default = 40), page_size: (max size = 3000), list: (:top || :online)



36
37
38
39
40
41
# File 'lib/spacer/client.rb', line 36

def friends(user_id, page=nil, page_size=nil, list=nil)
  response = do_request "users/#{user_id}/friends.#{FORMAT.to_s}?page=#{page}&page_size=#{page_size}&list=#{list.to_s}"
  @friends = response['friends'].map do |friend|
    User.from_hash_with_client(friend, self)
  end
end

#friendship?(user_id, friend_ids) ⇒ Boolean

Returns:

  • (Boolean)


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

def friendship?(user_id, friend_ids)
  multiple_friends = friend_ids.is_a?(Array)

  friend_ids = friend_ids.join(';') if multiple_friends
  response = do_request "users/#{user_id}/friends/#{friend_ids}"
  
  if multiple_friends
    @friendships = response['friendship'].map do |friendship|
      friendship['areFriends']
    end
  else
    response['friendship'].first['areFriends']
  end
end

#groups(user_id) ⇒ Object



121
122
123
124
125
126
# File 'lib/spacer/client.rb', line 121

def groups(user_id)
  response = do_request "users/#{user_id}/groups"
  @groups = response['Groups'].map do |group|
    Group.from_hash(group)
  end
end

#interests(user_id) ⇒ Object



69
70
71
72
# File 'lib/spacer/client.rb', line 69

def interests(user_id)
  response = do_request "users/#{user_id}/interests"
  @interests = Interest.from_hash(response)
end

#mood(user_id) ⇒ Object



101
102
103
104
# File 'lib/spacer/client.rb', line 101

def mood(user_id)
  response = do_request "users/#{user_id}/mood"
  @mood = Mood.from_hash(response)      
end

#photo(user_id, photo_id) ⇒ Object



91
92
93
94
# File 'lib/spacer/client.rb', line 91

def photo(user_id, photo_id)
  response = do_request "users/#{user_id}/photos/#{photo_id}"
  @photo = Photo.from_hash(response)
end

#photos(user_id) ⇒ Object



62
63
64
65
66
67
# File 'lib/spacer/client.rb', line 62

def photos(user_id)
  response = do_request "users/#{user_id}/photos"
  @photos = response['photos'].map do |photo|
    Photo.from_hash(photo)
  end      
end

#photos_for_album(user_id, album_id) ⇒ Object



55
56
57
58
59
60
# File 'lib/spacer/client.rb', line 55

def photos_for_album(user_id, album_id)
  response = do_request "users/#{user_id}/albums/#{album_id}/photos"
  @photos = response['photos'].map do |photo|
    Photo.from_hash(photo)
  end
end

#profile(user_id) ⇒ Object



25
26
27
28
# File 'lib/spacer/client.rb', line 25

def profile(user_id)
  response = do_request "users/#{user_id}/profile"
  @profile = Profile.from_hash(response)
end

#status(user_id) ⇒ Object



96
97
98
99
# File 'lib/spacer/client.rb', line 96

def status(user_id)
  response = do_request "users/#{user_id}/status"
  @status = Status.from_hash(response)
end

#user(user_id) ⇒ Object



20
21
22
23
# File 'lib/spacer/client.rb', line 20

def user(user_id)
  response = do_request "users/#{user_id}"
  @user = User.from_hash_with_client(response, self)
end

#video(user_id, video_id) ⇒ Object



86
87
88
89
# File 'lib/spacer/client.rb', line 86

def video(user_id, video_id)
  response = do_request "users/#{user_id}/videos/#{video_id}"
  @video = Video.from_hash(response)
end

#videos(user_id) ⇒ Object



79
80
81
82
83
84
# File 'lib/spacer/client.rb', line 79

def videos(user_id)
  response = do_request "users/#{user_id}/videos"
  @videos = response['videos'].map do |video|
    Video.from_hash(video)
  end            
end