Module: Graham::API

Includes:
Connection
Included in:
Graham
Defined in:
lib/graham/api.rb,
lib/graham/api/connection.rb

Defined Under Namespace

Modules: Connection

Instance Method Summary collapse

Methods included from Connection

#delete, #get, #post

Instance Method Details

#add_comment(media_id, comment_text) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/graham/api.rb', line 102

def add_comment(media_id, comment_text)
  url = "/v1/media/#{media_id}/comments"
  encoded_text = URI.encode(comment_text)
  post(url, {text: encoded_text}) do |res, body|
    yield(res, body) if block_given?
  end
end

#add_like(media_id) ⇒ Object



81
82
83
84
85
86
# File 'lib/graham/api.rb', line 81

def add_like(media_id)
  url = "/v1/media/#{media_id}/likes"
  post(url) do |res, body|
    yield(res, body) if block_given?
  end
end

#comments(media_id) ⇒ Object



95
96
97
98
99
100
# File 'lib/graham/api.rb', line 95

def comments(media_id)
  url = "/v1/media/#{media_id}/comments"
  get(url) do |res, body|
    yield(res, body) if block_given?
  end
end

#delete_comment(media_id, comment_id) ⇒ Object



110
111
112
113
114
115
# File 'lib/graham/api.rb', line 110

def delete_comment(media_id, comment_id)
  url = "/v1/media/#{media_id}/comments/#{comment_id}"
  delete(url) do |res, body|
    yield(res, body) if block_given?
  end
end

#delete_like(media_id, like_id) ⇒ Object



88
89
90
91
92
93
# File 'lib/graham/api.rb', line 88

def delete_like(media_id, like_id)
  url = "/v1/media/#{media_id}/likes"
  delete(url) do |res, body|
    yield(res, body) if block_given?
  end
end

#get_access_token(code) {|token| ... } ⇒ Object

Yields:

  • (token)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/graham/api.rb', line 8

def get_access_token(code)
  url = '/oauth/access_token'
  res = post(url, {
    client_id: config.client_id,
    client_secret: config.client_secret,
    grant_type: 'authorization_code',
    redirect_uri: config.redirect_uri,
    code: code
    })

  token = nil
  if res.success?
    body = JSON.parse res.body
    token = body["access_token"]
    config.access_token = token
  end
  yield(token) if block_given?
  token
end

#likes(media_id) ⇒ Object



74
75
76
77
78
79
# File 'lib/graham/api.rb', line 74

def likes(media_id)
  url = "/v1/media/#{media_id}/likes"
  get(url) do |res, body|
    yield(res, body) if block_given?
  end
end

#locations_search_by_fb_place_id(location) ⇒ Object



117
118
119
120
121
122
# File 'lib/graham/api.rb', line 117

def locations_search_by_fb_place_id(location)
  url = "/v1/locations/search"
  get(url, {facebook_places_id: location}) do |res, body|
    yield(res, body) if block_given?
  end
end

#locations_search_by_lat_lng(lat, lng) ⇒ Object



124
125
126
127
128
129
# File 'lib/graham/api.rb', line 124

def locations_search_by_lat_lng(lat, lng)
  url = "/v1/locations/search"
  get(url, {lat: lat, lng: lng}) do |res, body|
    yield(res, body) if block_given?
  end
end

#tags_info(tagname) ⇒ Object



49
50
51
52
53
54
# File 'lib/graham/api.rb', line 49

def tags_info(tagname)
  url                         = "/v1/tags/#{tagname}"
  get(url) do |res, body|
    yield(res, body) if block_given?
  end      
end

#tags_recent(tagname, count = -1,, min_tag_id = -1,, max_tag_id = -1)) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/graham/api.rb', line 56

def tags_recent(tagname, count = -1, min_tag_id = -1, max_tag_id = -1)
  url                         = "/v1/tags/#{tagname}/media/recent"
  options                     = {}
  options["count"]            = count if count >= 0
  options["min_tag_id"]       = min_tag_id if min_tag_id >= 0
  options["max_tag_id"]       = max_tag_id if max_tag_id >= 0
  get(url, options) do |res, body|
    yield(res, body) if block_given?
  end
end

#tags_search(tagname) ⇒ Object



67
68
69
70
71
72
# File 'lib/graham/api.rb', line 67

def tags_search(tagname)
  url                         = "/v1/tags/search"
  get(url, {q: tagname}) do |res, body|
    yield(res, body) if block_given?
  end
end

#users(userid) ⇒ Object



28
29
30
31
32
33
# File 'lib/graham/api.rb', line 28

def users(userid)
  url = "/v1/users/#{userid}"
  get(url) do |res, body|
    yield(res, body) if block_given?
  end
end

#users_recent(userid) ⇒ Object



35
36
37
38
39
40
# File 'lib/graham/api.rb', line 35

def users_recent(userid)
  url = "/v1/users/#{userid}/media/recent"
  get(url) do |res, body|
    yield(res, body) if block_given?
  end
end

#users_search(username) ⇒ Object



42
43
44
45
46
47
# File 'lib/graham/api.rb', line 42

def users_search(username)
  url = "/v1/users/search"
  get(url, {q: username}) do |res, body|
    yield(res, body) if block_given?
  end
end