flickr_oauth 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -0
- data/flickr_oauth.gemspec +3 -1
- data/lib/flickr.rb +188 -1
- data/lib/flickr/client.rb +17 -46
- data/lib/flickr/client/authentication.rb +17 -0
- data/lib/flickr/client/connection.rb +44 -0
- data/lib/flickr/client/requests.rb +69 -0
- data/lib/flickr/client/upload.rb +22 -0
- data/lib/flickr/node.rb +2 -28
- data/lib/flickr_oauth/version.rb +1 -1
- data/spec/.DS_Store +0 -0
- data/spec/fixtures/.DS_Store +0 -0
- data/spec/fixtures/cassettes/.DS_Store +0 -0
- data/spec/fixtures/cassettes/flickr_reflection_getMethodInfo/_format_json.yml +133 -0
- data/spec/fixtures/cassettes/flickr_reflection_getMethodInfo/_format_rest.yml +133 -0
- data/spec/fixtures/cassettes/flickr_reflection_getMethods/.yml +65 -0
- data/spec/fixtures/cassettes/flickr_reflection_getMethods/_format_json.yml +65 -0
- data/spec/fixtures/cassettes/flickr_reflection_getMethods/_format_rest.yml +64 -0
- data/spec/fixtures/cassettes/{JSON_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/with_oauth_token.yml → flickr_test_echo/_format_json.yml} +12 -12
- data/spec/fixtures/cassettes/{REST_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/with_oauth_token.yml → flickr_test_echo/_format_rest.yml} +13 -13
- data/spec/fixtures/cassettes/flickr_upload.yml +1798 -0
- data/spec/fixtures/test.jpg +0 -0
- data/spec/fixtures/test_2.jpg +0 -0
- data/spec/flickr/reflection/getMethodInfo_spec.rb +73 -0
- data/spec/flickr/reflection/getMethods_spec.rb +53 -0
- data/spec/flickr/test/echo_spec.rb +51 -0
- data/spec/flickr/upload_spec.rb +33 -0
- data/spec/spec_helper.rb +4 -5
- metadata +70 -25
- data/spec/fixtures/cassettes/JSON_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/no_oauth_token.yml +0 -40
- data/spec/fixtures/cassettes/REST_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/no_oauth_token.yml +0 -39
- data/spec/json/flickr_spec.rb +0 -6
- data/spec/rest/flickr_spec.rb +0 -6
- data/spec/shared_examples.rb +0 -65
data/README.md
CHANGED
@@ -28,6 +28,20 @@ Or, you can use the `flickr` method:
|
|
28
28
|
:token_secret => OAUTH_ACCESS_TOKEN_SECRET,
|
29
29
|
:format => :json
|
30
30
|
)
|
31
|
+
|
32
|
+
For photo upload:
|
33
|
+
|
34
|
+
flickr.upload(
|
35
|
+
PATH_TO_IMAGE_FILE
|
36
|
+
:title => 'test upload', # optional
|
37
|
+
:description => 'this is a test', # optional
|
38
|
+
:tags => 'test upload', # optional
|
39
|
+
:content_type => 'image/jpeg', # optional
|
40
|
+
:consumer_key => CONSUMER_KEY,
|
41
|
+
:consumer_secret => CONSUMER_SECRET,
|
42
|
+
:token => OAUTH_ACCESS_TOKEN,
|
43
|
+
:token_secret => OAUTH_ACCESS_TOKEN_SECRET
|
44
|
+
)
|
31
45
|
|
32
46
|
TODO
|
33
47
|
-
|
data/flickr_oauth.gemspec
CHANGED
@@ -23,8 +23,10 @@ Gem::Specification.new do |s|
|
|
23
23
|
|
24
24
|
s.add_dependency 'faraday', '>= 0.7'
|
25
25
|
s.add_dependency 'faraday_middleware', '>= 0.7.0.rc1'
|
26
|
-
s.add_dependency '
|
26
|
+
s.add_dependency 'mime-types'
|
27
|
+
s.add_dependency 'multipart-post'
|
27
28
|
s.add_dependency 'multi_json'
|
29
|
+
s.add_dependency 'multi_xml'
|
28
30
|
s.add_dependency 'simple_oauth'
|
29
31
|
s.add_development_dependency 'rspec', '>= 2.6'
|
30
32
|
s.add_development_dependency 'webmock', '>= 1.6'
|
data/lib/flickr.rb
CHANGED
@@ -3,9 +3,196 @@ require 'flickr/client'
|
|
3
3
|
module Flickr
|
4
4
|
extend self
|
5
5
|
|
6
|
+
DEFAULT_ENDPOINT = 'http://api.flickr.com'.freeze
|
7
|
+
SECURE_ENDPOINT = 'https://secure.flickr.com'.freeze
|
8
|
+
REST_PATH = '/services/rest'.freeze
|
9
|
+
UPLOAD_PATH = '/services/upload'.freeze
|
10
|
+
REPLACE_PATH = '/services/replace'.freeze
|
11
|
+
|
12
|
+
METHODS = %w(
|
13
|
+
flickr.activity.userComments
|
14
|
+
flickr.activity.userPhotos
|
15
|
+
flickr.auth.checkToken
|
16
|
+
flickr.auth.getFrob
|
17
|
+
flickr.auth.getFullToken
|
18
|
+
flickr.auth.getToken
|
19
|
+
flickr.auth.oauth.getAccessToken
|
20
|
+
flickr.blogs.getList
|
21
|
+
flickr.blogs.getServices
|
22
|
+
flickr.blogs.postPhoto
|
23
|
+
flickr.collections.getInfo
|
24
|
+
flickr.collections.getTree
|
25
|
+
flickr.commons.getInstitutions
|
26
|
+
flickr.contacts.getList
|
27
|
+
flickr.contacts.getListRecentlyUploaded
|
28
|
+
flickr.contacts.getPublicList
|
29
|
+
flickr.favorites.add
|
30
|
+
flickr.favorites.getList
|
31
|
+
flickr.favorites.getPublicList
|
32
|
+
flickr.favorites.remove
|
33
|
+
flickr.galleries.addPhoto
|
34
|
+
flickr.galleries.create
|
35
|
+
flickr.galleries.editMeta
|
36
|
+
flickr.galleries.editPhoto
|
37
|
+
flickr.galleries.editPhotos
|
38
|
+
flickr.galleries.getInfo
|
39
|
+
flickr.galleries.getList
|
40
|
+
flickr.galleries.getListForPhoto
|
41
|
+
flickr.galleries.getPhotos
|
42
|
+
flickr.groups.browse
|
43
|
+
flickr.groups.getInfo
|
44
|
+
flickr.groups.members.getList
|
45
|
+
flickr.groups.pools.add
|
46
|
+
flickr.groups.pools.getContext
|
47
|
+
flickr.groups.pools.getGroups
|
48
|
+
flickr.groups.pools.getPhotos
|
49
|
+
flickr.groups.pools.remove
|
50
|
+
flickr.groups.search
|
51
|
+
flickr.interestingness.getList
|
52
|
+
flickr.machinetags.getNamespaces
|
53
|
+
flickr.machinetags.getPairs
|
54
|
+
flickr.machinetags.getPredicates
|
55
|
+
flickr.machinetags.getRecentValues
|
56
|
+
flickr.machinetags.getValues
|
57
|
+
flickr.panda.getList
|
58
|
+
flickr.panda.getPhotos
|
59
|
+
flickr.people.findByEmail
|
60
|
+
flickr.people.findByUsername
|
61
|
+
flickr.people.getInfo
|
62
|
+
flickr.people.getPhotos
|
63
|
+
flickr.people.getPhotosOf
|
64
|
+
flickr.people.getPublicGroups
|
65
|
+
flickr.people.getPublicPhotos
|
66
|
+
flickr.people.getUploadStatus
|
67
|
+
flickr.photos.addTags
|
68
|
+
flickr.photos.comments.addComment
|
69
|
+
flickr.photos.comments.deleteComment
|
70
|
+
flickr.photos.comments.editComment
|
71
|
+
flickr.photos.comments.getList
|
72
|
+
flickr.photos.comments.getRecentForContacts
|
73
|
+
flickr.photos.delete
|
74
|
+
flickr.photos.geo.batchCorrectLocation
|
75
|
+
flickr.photos.geo.correctLocation
|
76
|
+
flickr.photos.geo.getLocation
|
77
|
+
flickr.photos.geo.getPerms
|
78
|
+
flickr.photos.geo.photosForLocation
|
79
|
+
flickr.photos.geo.removeLocation
|
80
|
+
flickr.photos.geo.setContext
|
81
|
+
flickr.photos.geo.setLocation
|
82
|
+
flickr.photos.geo.setPerms
|
83
|
+
flickr.photos.getAllContexts
|
84
|
+
flickr.photos.getContactsPhotos
|
85
|
+
flickr.photos.getContactsPublicPhotos
|
86
|
+
flickr.photos.getContext
|
87
|
+
flickr.photos.getCounts
|
88
|
+
flickr.photos.getExif
|
89
|
+
flickr.photos.getFavorites
|
90
|
+
flickr.photos.getInfo
|
91
|
+
flickr.photos.getNotInSet
|
92
|
+
flickr.photos.getPerms
|
93
|
+
flickr.photos.getRecent
|
94
|
+
flickr.photos.getSizes
|
95
|
+
flickr.photos.getUntagged
|
96
|
+
flickr.photos.getWithGeoData
|
97
|
+
flickr.photos.getWithoutGeoData
|
98
|
+
flickr.photos.licenses.getInfo
|
99
|
+
flickr.photos.licenses.setLicense
|
100
|
+
flickr.photos.notes.add
|
101
|
+
flickr.photos.notes.delete
|
102
|
+
flickr.photos.notes.edit
|
103
|
+
flickr.photos.people.add
|
104
|
+
flickr.photos.people.delete
|
105
|
+
flickr.photos.people.deleteCoords
|
106
|
+
flickr.photos.people.editCoords
|
107
|
+
flickr.photos.people.getList
|
108
|
+
flickr.photos.recentlyUpdated
|
109
|
+
flickr.photos.removeTag
|
110
|
+
flickr.photos.search
|
111
|
+
flickr.photos.setContentType
|
112
|
+
flickr.photos.setDates
|
113
|
+
flickr.photos.setMeta
|
114
|
+
flickr.photos.setPerms
|
115
|
+
flickr.photos.setSafetyLevel
|
116
|
+
flickr.photos.setTags
|
117
|
+
flickr.photos.transform.rotate
|
118
|
+
flickr.photos.upload.checkTickets
|
119
|
+
flickr.photosets.addPhoto
|
120
|
+
flickr.photosets.comments.addComment
|
121
|
+
flickr.photosets.comments.deleteComment
|
122
|
+
flickr.photosets.comments.editComment
|
123
|
+
flickr.photosets.comments.getList
|
124
|
+
flickr.photosets.create
|
125
|
+
flickr.photosets.delete
|
126
|
+
flickr.photosets.editMeta
|
127
|
+
flickr.photosets.editPhotos
|
128
|
+
flickr.photosets.getContext
|
129
|
+
flickr.photosets.getInfo
|
130
|
+
flickr.photosets.getList
|
131
|
+
flickr.photosets.getPhotos
|
132
|
+
flickr.photosets.orderSets
|
133
|
+
flickr.photosets.removePhoto
|
134
|
+
flickr.photosets.removePhotos
|
135
|
+
flickr.photosets.reorderPhotos
|
136
|
+
flickr.photosets.setPrimaryPhoto
|
137
|
+
flickr.places.find
|
138
|
+
flickr.places.findByLatLon
|
139
|
+
flickr.places.getChildrenWithPhotosPublic
|
140
|
+
flickr.places.getInfo
|
141
|
+
flickr.places.getInfoByUrl
|
142
|
+
flickr.places.getPlaceTypes
|
143
|
+
flickr.places.getShapeHistory
|
144
|
+
flickr.places.getTopPlacesList
|
145
|
+
flickr.places.placesForBoundingBox
|
146
|
+
flickr.places.placesForContacts
|
147
|
+
flickr.places.placesForTags
|
148
|
+
flickr.places.placesForUser
|
149
|
+
flickr.places.resolvePlaceId
|
150
|
+
flickr.places.resolvePlaceURL
|
151
|
+
flickr.places.tagsForPlace
|
152
|
+
flickr.prefs.getContentType
|
153
|
+
flickr.prefs.getGeoPerms
|
154
|
+
flickr.prefs.getHidden
|
155
|
+
flickr.prefs.getPrivacy
|
156
|
+
flickr.prefs.getSafetyLevel
|
157
|
+
flickr.reflection.getMethodInfo
|
158
|
+
flickr.reflection.getMethods
|
159
|
+
flickr.stats.getCollectionDomains
|
160
|
+
flickr.stats.getCollectionReferrers
|
161
|
+
flickr.stats.getCollectionStats
|
162
|
+
flickr.stats.getCSVFiles
|
163
|
+
flickr.stats.getPhotoDomains
|
164
|
+
flickr.stats.getPhotoReferrers
|
165
|
+
flickr.stats.getPhotosetDomains
|
166
|
+
flickr.stats.getPhotosetReferrers
|
167
|
+
flickr.stats.getPhotosetStats
|
168
|
+
flickr.stats.getPhotoStats
|
169
|
+
flickr.stats.getPhotostreamDomains
|
170
|
+
flickr.stats.getPhotostreamReferrers
|
171
|
+
flickr.stats.getPhotostreamStats
|
172
|
+
flickr.stats.getPopularPhotos
|
173
|
+
flickr.stats.getTotalViews
|
174
|
+
flickr.tags.getClusterPhotos
|
175
|
+
flickr.tags.getClusters
|
176
|
+
flickr.tags.getHotList
|
177
|
+
flickr.tags.getListPhoto
|
178
|
+
flickr.tags.getListUser
|
179
|
+
flickr.tags.getListUserPopular
|
180
|
+
flickr.tags.getListUserRaw
|
181
|
+
flickr.tags.getRelated
|
182
|
+
flickr.test.echo
|
183
|
+
flickr.test.login
|
184
|
+
flickr.test.null
|
185
|
+
flickr.urls.getGroup
|
186
|
+
flickr.urls.getUserPhotos
|
187
|
+
flickr.urls.getUserProfile
|
188
|
+
flickr.urls.lookupGallery
|
189
|
+
flickr.urls.lookupGroup
|
190
|
+
flickr.urls.lookupUser
|
191
|
+
)
|
192
|
+
|
6
193
|
def new(options = {})
|
7
194
|
Flickr::Client.new(options)
|
8
|
-
end
|
195
|
+
end
|
9
196
|
end
|
10
197
|
|
11
198
|
def flickr
|
data/lib/flickr/client.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
1
|
+
require 'flickr/client/authentication'
|
2
|
+
require 'flickr/client/connection'
|
3
|
+
require 'flickr/client/requests'
|
4
|
+
require 'flickr/client/upload'
|
5
|
+
|
4
6
|
require 'flickr/node'
|
5
7
|
|
6
|
-
module Flickr
|
8
|
+
module Flickr
|
7
9
|
class Client
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
REPLACE_PATH = '/services/resplace'.freeze
|
10
|
+
include Flickr::Client::Authentication
|
11
|
+
include Flickr::Client::Connection
|
12
|
+
include Flickr::Client::Requests
|
13
|
+
include Flickr::Client::Upload
|
13
14
|
|
14
15
|
CONFIGURATION_KEYS = [
|
15
16
|
:consumer_key,
|
@@ -18,8 +19,9 @@ module Flickr
|
|
18
19
|
:token_secret,
|
19
20
|
:secure,
|
20
21
|
:format,
|
21
|
-
:enable_logging
|
22
|
-
|
22
|
+
:enable_logging,
|
23
|
+
:normalize
|
24
|
+
]
|
23
25
|
|
24
26
|
attr_accessor *CONFIGURATION_KEYS
|
25
27
|
|
@@ -30,46 +32,15 @@ module Flickr
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def endpoint(secure = false)
|
33
|
-
secure or self.secure ? SECURE_ENDPOINT : DEFAULT_ENDPOINT
|
34
|
-
end
|
35
|
-
|
36
|
-
def authentication(options = {})
|
37
|
-
{
|
38
|
-
:consumer_key => consumer_key,
|
39
|
-
:consumer_secret => consumer_secret,
|
40
|
-
:token => token,
|
41
|
-
:token_secret => token_secret
|
42
|
-
}.merge(options.select{|k,v| [:consumer_key, :consumer_secret, :token, :token_secret].include?(k.to_sym)})
|
43
|
-
end
|
44
|
-
|
45
|
-
def adapter
|
46
|
-
@adapter || Faraday.default_adapter
|
47
|
-
end
|
48
|
-
|
49
|
-
def connection(options = {})
|
50
|
-
@connection = Faraday.new(:url => endpoint(options[:secure])) do |builder|
|
51
|
-
builder.use Faraday::Request::OAuth, authentication(options)
|
52
|
-
builder.use Faraday::Request::Multipart
|
53
|
-
builder.use Faraday::Request::UrlEncoded
|
54
|
-
|
55
|
-
builder.use Faraday::Response::RaiseFlickrError
|
56
|
-
if (options[:format] or format).to_s == 'json'
|
57
|
-
builder.use Faraday::Response::ParseJson
|
58
|
-
else
|
59
|
-
builder.use Faraday::Response::ParseXml
|
60
|
-
end
|
61
|
-
builder.use Faraday::Response::RaiseError
|
62
|
-
builder.use Faraday::Response::Logger if options[:enable_logging] or enable_logging
|
63
|
-
|
64
|
-
builder.adapter adapter
|
65
|
-
end
|
35
|
+
secure or self.secure ? Flickr::SECURE_ENDPOINT : Flickr::DEFAULT_ENDPOINT
|
66
36
|
end
|
67
37
|
|
68
|
-
protected
|
38
|
+
protected
|
69
39
|
|
70
40
|
def method_missing(method_name, *args)
|
41
|
+
# super unless ['reflection'].include?(method_name.to_s)
|
71
42
|
args.empty? ? Flickr::Node.new(self, ['flickr', method_name].join('.')) : super
|
72
|
-
end
|
43
|
+
end
|
73
44
|
|
74
45
|
end
|
75
46
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Flickr
|
2
|
+
class Client
|
3
|
+
module Authentication
|
4
|
+
AUTHENTICATION_KEYS = [:consumer_key, :consumer_secret, :token, :token_secret]
|
5
|
+
|
6
|
+
def authentication_options(options = {})
|
7
|
+
{
|
8
|
+
:consumer_key => consumer_key,
|
9
|
+
:consumer_secret => consumer_secret,
|
10
|
+
:token => token,
|
11
|
+
:token_secret => token_secret
|
12
|
+
}.merge(options.select{|k,v| AUTHENTICATION_KEYS.include?(k.to_sym)})
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'faraday/response/raise_flickr_error'
|
4
|
+
|
5
|
+
module Flickr
|
6
|
+
class Client
|
7
|
+
module Connection
|
8
|
+
|
9
|
+
def connection(options = {})
|
10
|
+
@connection = Faraday.new(:url => endpoint(options[:secure])) do |builder|
|
11
|
+
builder.use Faraday::Request::OAuth, authentication_options(options)
|
12
|
+
builder.use Faraday::Request::Multipart
|
13
|
+
builder.use Faraday::Request::UrlEncoded
|
14
|
+
|
15
|
+
builder.use Faraday::Response::RaiseFlickrError
|
16
|
+
if (options[:format] or format).to_s == 'json'
|
17
|
+
builder.use Faraday::Response::ParseJson
|
18
|
+
else
|
19
|
+
builder.use Faraday::Response::ParseXml
|
20
|
+
end
|
21
|
+
builder.use Faraday::Response::RaiseError
|
22
|
+
builder.use Faraday::Response::Logger if options[:enable_logging] or enable_logging
|
23
|
+
|
24
|
+
builder.adapter adapter
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def adapter
|
29
|
+
@adapter || Faraday.default_adapter
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def extract_connection_options(params = {})
|
35
|
+
CONFIGURATION_KEYS.inject({}) do |options, k|
|
36
|
+
if params.has_key?(k)
|
37
|
+
options[k.to_sym] = (k == :format ? params.fetch(k) : params.delete(k))
|
38
|
+
end
|
39
|
+
options
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Flickr
|
2
|
+
class Client
|
3
|
+
module Requests
|
4
|
+
|
5
|
+
def get(path, params = {})
|
6
|
+
request :get, path, params
|
7
|
+
end
|
8
|
+
|
9
|
+
def post(path, params = {})
|
10
|
+
request :post, path, params
|
11
|
+
end
|
12
|
+
|
13
|
+
def put(path, params = {})
|
14
|
+
request :put, path, params
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete(path, params = {})
|
18
|
+
request :delete, path, params
|
19
|
+
end
|
20
|
+
|
21
|
+
def request(method, path, params = {})
|
22
|
+
params = params.dup
|
23
|
+
options = extract_connection_options(params)
|
24
|
+
|
25
|
+
if method.to_sym == :get
|
26
|
+
response = connection(options).send(method, build_rest_query(path, params))
|
27
|
+
else
|
28
|
+
response = connection(options).send(method, path, params)
|
29
|
+
end
|
30
|
+
|
31
|
+
if options[:normalize]
|
32
|
+
options[:format].to_s == 'json' ? normalize_json(response.body) : normalize_xml(response.body)
|
33
|
+
else
|
34
|
+
response.body
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def build_rest_query(path, params = {})
|
41
|
+
params[:format] ||= self.format
|
42
|
+
params[:nojsoncallback] = (params[:format].to_s == 'json' ? 1 : nil)
|
43
|
+
query = params.map{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" unless v.nil?}.compact.join("&")
|
44
|
+
[path, query].join("?")
|
45
|
+
end
|
46
|
+
|
47
|
+
def normalize_json(raw)
|
48
|
+
if raw.is_a?(Hash)
|
49
|
+
if raw.keys.size == 1 and raw.has_key?('_content')
|
50
|
+
raw['_content']
|
51
|
+
else
|
52
|
+
raw.each_pair do |k, v|
|
53
|
+
raw[k] = normalize_json(v)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
elsif raw.is_a?(Array)
|
57
|
+
raw.collect{|r| normalize_json(r) }
|
58
|
+
else
|
59
|
+
raw
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def normalize_xml(xml_result)
|
64
|
+
xml_result['rsp']
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|