Module: Flickrie::Callable

Included in:
ApiMethods
Defined in:
lib/flickrie/callable.rb

Instance Method Summary collapse

Instance Method Details

#clientHTTP response

This is for manual use (for example, if I haven't covered something yet, and you really need it). Here's an example:

response = Flickrie.client.get "flickr.photos.getInfo", photo_id: 8423943
response.body['photo']['id']          # => 8423943
response.body['photo']['description'] # => "..."

Flickrie.client.post "flickr.photos.licenses.setLicense", photo_id: 1241497, license_id: 2

For the full list of available API methods, see this page.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/flickrie/callable.rb', line 20

def client
  params = {
    url: 'https://api.flickr.com/services/rest',
    params: {
      format: 'json',
      nojsoncallback: '1',
      api_key: api_key
    },
    request: {
      open_timeout: open_timeout || DEFAULTS[:open_timeout],
      timeout: timeout || DEFAULTS[:timeout]
    }
  }

  @client ||=
    Client.new(params) do |b|
      b.use Middleware::Retry
      b.use FaradayMiddleware::OAuth,
        consumer_key: api_key,
        consumer_secret: shared_secret,
        token: access_token,
        token_secret: access_secret

      b.use Middleware::FixFlickrData
      b.use Middleware::StatusCheck
      b.use FaradayMiddleware::ParseJson
      b.use Middleware::OAuthCheck

      b.adapter :net_http
    end
end

#upload_clientObject


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/flickrie/callable.rb', line 52

def upload_client
  params = {
    url: 'https://api.flickr.com/services',
    request: {
      open_timeout: open_timeout || DEFAULTS[:open_timeout]
    }
  }

  @upload_client ||=
    UploadClient.new(params) do |b|
      b.use Middleware::Retry
      b.use FaradayMiddleware::OAuth,
        consumer_key: api_key,
        consumer_secret: shared_secret,
        token: access_token,
        token_secret: access_secret
      b.request :multipart

      b.use Middleware::UploadStatusCheck
      b.use FaradayMiddleware::ParseXml
      b.use Middleware::OAuthCheck

      b.adapter :net_http
    end
end