yandex-api-fotki 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -3
- data/README.md +1 -1
- data/lib/yandex/api/fotki.rb +123 -9
- data/lib/yandex/api/fotki/version.rb +1 -1
- data/yandex-api-fotki.gemspec +3 -3
- metadata +11 -16
- data/lib/yandex/api/fotki/album.rb +0 -24
- data/lib/yandex/api/fotki/albums.rb +0 -36
- data/lib/yandex/api/fotki/me.rb +0 -26
- data/lib/yandex/api/fotki/photo.rb +0 -25
- data/lib/yandex/api/fotki/photos.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aee299768c5b7267a58060a46da1fdc3dd3f48e3
|
4
|
+
data.tar.gz: 2a5d500310cbe31825942626aad39d080c9181bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2ad9e34b57e4d9d7617a9cf83bcd46a5e6143cc952b9d4d0bf70b3c9f69eb4eb0413429466ec92729b5a9fd1e2a3a40a6080dac326e9e23967a96d23aeaa397
|
7
|
+
data.tar.gz: fd9fab21b806ad41f6f1ebf2aff014642bd1a6203b0dd51e00d92594f49e2fab630ef0d797acddd6094140b875d575a975ca9dbe88fd34a77f4ab0f601334121
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Yandex::Api::Fotki
|
2
2
|
|
3
3
|
[](https://rubygems.org/gems/yandex-api-fotki)
|
4
|
-
[](https://travis-ci.org/1v/yandex-api-fotki)
|
5
5
|
[](https://gemnasium.com/github.com/1v/yandex-api-fotki)
|
6
6
|
[](https://codeclimate.com/github/1v/yandex-api-fotki)
|
7
7
|
[](https://codeclimate.com/github/1v/yandex-api-fotki/coverage)
|
data/lib/yandex/api/fotki.rb
CHANGED
@@ -1,17 +1,11 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
require 'active_support/core_ext/hash/conversions'
|
3
3
|
|
4
|
-
|
5
|
-
require_relative 'fotki/me'
|
6
|
-
require_relative 'fotki/albums'
|
7
|
-
require_relative 'fotki/album'
|
8
|
-
require_relative 'fotki/photos'
|
9
|
-
require_relative 'fotki/photo'
|
4
|
+
require 'yandex/api/fotki/version'
|
10
5
|
|
11
6
|
module Yandex
|
12
7
|
module API
|
13
8
|
module Fotki
|
14
|
-
API_HOST = 'http://api-fotki.yandex.ru'
|
15
9
|
class RuntimeError < RuntimeError ; end
|
16
10
|
#
|
17
11
|
# Main method for authentification
|
@@ -22,9 +16,9 @@ module Yandex
|
|
22
16
|
# @see https://tech.yandex.ru/oauth/doc/dg/reference/web-client-docpage/
|
23
17
|
#
|
24
18
|
def self.oauth(oauth_code)
|
25
|
-
return self
|
19
|
+
return self unless @api_urls.nil?
|
26
20
|
@oauth_code = oauth_code
|
27
|
-
me = RestClient.get(
|
21
|
+
me = RestClient.get('http://api-fotki.yandex.ru/api/me/',
|
28
22
|
Fotki.oauth_hash)
|
29
23
|
@api_urls = Me.new(me)
|
30
24
|
self
|
@@ -72,6 +66,126 @@ module Yandex
|
|
72
66
|
Photos
|
73
67
|
end
|
74
68
|
#
|
69
|
+
# Class Me is wrapper for user service document
|
70
|
+
#
|
71
|
+
# @see https://tech.yandex.ru/fotki/doc/operations-ref/service-document-get-docpage/
|
72
|
+
#
|
73
|
+
class Me
|
74
|
+
attr_reader :album, :photo, :tag
|
75
|
+
#
|
76
|
+
# Parse response from Fotki.oauth
|
77
|
+
#
|
78
|
+
# @param [RestClient::Response] response
|
79
|
+
#
|
80
|
+
def initialize(response)
|
81
|
+
# Nokogiri::XML(me).xpath("/app:service/app:workspace/app:collection[@id='album-list']/@href").text
|
82
|
+
collention = Fotki.xml_to_hash(response)['service']['workspace']['collection'].map{ |i| { i['id'] => i['href'] }}.inject(:merge)
|
83
|
+
@album = collention['album-list']
|
84
|
+
@photo = collention['photo-list']
|
85
|
+
@tag = collention['tag-list']
|
86
|
+
end
|
87
|
+
end
|
88
|
+
#
|
89
|
+
# Class Albums is wrapper for albums listing
|
90
|
+
#
|
91
|
+
class Albums
|
92
|
+
#
|
93
|
+
# List user albums
|
94
|
+
#
|
95
|
+
# @param [Hash] options
|
96
|
+
# @option options [String] sort updated or rupdated or published or rpublished
|
97
|
+
# @option options [Integer] offset Not implemented
|
98
|
+
# @option options [Integer] limit 100 is max
|
99
|
+
#
|
100
|
+
# @return [Hash] Hash of Fotki::Album were keys is id of album
|
101
|
+
# @see https://tech.yandex.ru/fotki/doc/operations-ref/albums-collection-get-docpage/
|
102
|
+
#
|
103
|
+
def self.list(options = {})
|
104
|
+
options[:sort] ||= 'updated'
|
105
|
+
options[:offset] ||= 0
|
106
|
+
options[:limit] ||= 10
|
107
|
+
|
108
|
+
return @list_cache if !@list_cache.nil? && options === @list_options_cache
|
109
|
+
|
110
|
+
@list_options_cache = options
|
111
|
+
|
112
|
+
list = RestClient.get("#{Fotki.api_urls.album}#{options[:sort]}/?limit=#{options[:limit]}", Fotki.oauth_hash)
|
113
|
+
|
114
|
+
@list_cache = Fotki.xml_to_hash(list)['feed']['entry']
|
115
|
+
@list_cache = @list_cache.map { |i|
|
116
|
+
album = Album.new(i)
|
117
|
+
{ album.id => album }
|
118
|
+
}.inject(:merge)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
#
|
122
|
+
# Class Album is wrapper for single album
|
123
|
+
#
|
124
|
+
class Album
|
125
|
+
attr_reader :id, :title, :link
|
126
|
+
#
|
127
|
+
# <description>
|
128
|
+
#
|
129
|
+
# @param [Hash] hash Hash from {Fotki::Albums.list} response
|
130
|
+
#
|
131
|
+
def initialize(hash)
|
132
|
+
@id = parse_id(hash['id'])
|
133
|
+
@title = hash['title']
|
134
|
+
@link = hash['link'].map{ |i| { i['rel'] => i['href'] } }.inject(:merge)
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
def parse_id(string)
|
139
|
+
string.split(':').last.to_i
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
#
|
144
|
+
# Class Photos provides photos collections
|
145
|
+
#
|
146
|
+
class Photos
|
147
|
+
#
|
148
|
+
# Uploading photo
|
149
|
+
#
|
150
|
+
# @param [Hash] hash
|
151
|
+
#
|
152
|
+
# == Required
|
153
|
+
# @option hash [File] :image IO stream of file. For example +File.new('tmp/file.png')+ or +open('\h\ttp://site.com/image.png')+
|
154
|
+
# == Optional
|
155
|
+
# @option hash [String] :title Title of image
|
156
|
+
# @option hash [String] :summary Description of image
|
157
|
+
# @option hash [Integer] :album Id of album to upload
|
158
|
+
# @option hash [String] :access public, friends or private
|
159
|
+
# @see https://tech.yandex.ru/fotki/doc/concepts/add-photo-docpage/#multipart-format
|
160
|
+
#
|
161
|
+
# @return [Fotki::Photo] Instance of Photo class
|
162
|
+
#
|
163
|
+
def self.upload(hash)
|
164
|
+
raise Fotki::RuntimeError, ':image is required' unless hash[:image]
|
165
|
+
response = RestClient.post(Fotki.api_urls.photo, hash, Fotki.oauth_hash)
|
166
|
+
Photo.new(response)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
#
|
170
|
+
# Class Photo is wrapper for single photo
|
171
|
+
#
|
172
|
+
# @see https://tech.yandex.ru/fotki/doc/operations-ref/photo-get-docpage/
|
173
|
+
#
|
174
|
+
class Photo
|
175
|
+
attr_reader :id, :links
|
176
|
+
#
|
177
|
+
# Photo initialize
|
178
|
+
#
|
179
|
+
# @param [RestClient::Response] response
|
180
|
+
#
|
181
|
+
def initialize(response)
|
182
|
+
entry = Fotki.xml_to_hash(response)['entry']
|
183
|
+
@id = entry['id'].split(':').last.to_i
|
184
|
+
@links = entry['img'].map{ |i| { i['size'] => i } }.inject(:merge)
|
185
|
+
# puts JSON.pretty_generate(entry)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
#
|
75
189
|
# XML parser wrapper. Because I'm not sure if it be persistent.
|
76
190
|
#
|
77
191
|
# @param [String] xml XML input
|
data/yandex-api-fotki.gemspec
CHANGED
@@ -21,10 +21,10 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.required_ruby_version = '>=
|
24
|
+
spec.required_ruby_version = '>= 2.2.2'
|
25
25
|
|
26
|
-
spec.add_runtime_dependency "activesupport", "
|
27
|
-
spec.add_runtime_dependency "rest-client", "
|
26
|
+
spec.add_runtime_dependency "activesupport", ">= 4.0.0"
|
27
|
+
spec.add_runtime_dependency "rest-client", "~> 2.0"
|
28
28
|
|
29
29
|
spec.add_development_dependency "bundler", "~> 1.13"
|
30
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yandex-api-fotki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- github.com/1v
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '2'
|
33
|
+
version: '2.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '2'
|
40
|
+
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,11 +128,6 @@ files:
|
|
128
128
|
- bin/setup
|
129
129
|
- lib/yandex-api-fotki.rb
|
130
130
|
- lib/yandex/api/fotki.rb
|
131
|
-
- lib/yandex/api/fotki/album.rb
|
132
|
-
- lib/yandex/api/fotki/albums.rb
|
133
|
-
- lib/yandex/api/fotki/me.rb
|
134
|
-
- lib/yandex/api/fotki/photo.rb
|
135
|
-
- lib/yandex/api/fotki/photos.rb
|
136
131
|
- lib/yandex/api/fotki/version.rb
|
137
132
|
- yandex-api-fotki.gemspec
|
138
133
|
homepage: https://github.com/1v/yandex-api-fotki
|
@@ -147,7 +142,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
142
|
requirements:
|
148
143
|
- - ">="
|
149
144
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
145
|
+
version: 2.2.2
|
151
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
147
|
requirements:
|
153
148
|
- - ">="
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Yandex
|
2
|
-
module API
|
3
|
-
module Fotki
|
4
|
-
class Album
|
5
|
-
attr_reader :id, :title, :link
|
6
|
-
#
|
7
|
-
# <description>
|
8
|
-
#
|
9
|
-
# @param [Hash] options Hash from {Fotki::Albums.list} response
|
10
|
-
#
|
11
|
-
def initialize(options)
|
12
|
-
@id = parse_id(options['id'])
|
13
|
-
@title = options['title']
|
14
|
-
@link = options['link'].map{ |i| { i['rel'] => i['href'] } }.inject(:merge)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
def parse_id(string)
|
19
|
-
string.split(':').last.to_i
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Yandex
|
2
|
-
module API
|
3
|
-
module Fotki
|
4
|
-
class Albums
|
5
|
-
#
|
6
|
-
# List user albums
|
7
|
-
#
|
8
|
-
# @param [Hash] options
|
9
|
-
# @option options [String] sort updated or rupdated or published or rpublished
|
10
|
-
# @option options [Integer] offset Not implemented
|
11
|
-
# @option options [Integer] limit 100 is max
|
12
|
-
#
|
13
|
-
# @return [Hash] Hash of Fotki::Album were keys is id of album
|
14
|
-
# @see https://tech.yandex.ru/fotki/doc/operations-ref/albums-collection-get-docpage/
|
15
|
-
#
|
16
|
-
def self.list(options = {})
|
17
|
-
options[:sort] ||= 'updated'
|
18
|
-
options[:offset] ||= 0
|
19
|
-
options[:limit] ||= 10
|
20
|
-
|
21
|
-
return @list_cache if !@list_cache.nil? && options === @list_options_cache
|
22
|
-
|
23
|
-
@list_options_cache = options
|
24
|
-
|
25
|
-
list = RestClient.get("#{Fotki.api_urls.album}#{options[:sort]}/?limit=#{options[:limit]}", Fotki.oauth_hash)
|
26
|
-
|
27
|
-
@list_cache = Fotki.xml_to_hash(list)['feed']['entry']
|
28
|
-
@list_cache = @list_cache.map { |i|
|
29
|
-
album = Album.new(i)
|
30
|
-
{ album.id => album }
|
31
|
-
}.inject(:merge)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
data/lib/yandex/api/fotki/me.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Yandex
|
2
|
-
module API
|
3
|
-
module Fotki
|
4
|
-
#
|
5
|
-
# Class Me is wrapper for user service document
|
6
|
-
#
|
7
|
-
# @see https://tech.yandex.ru/fotki/doc/operations-ref/service-document-get-docpage/
|
8
|
-
#
|
9
|
-
class Me
|
10
|
-
attr_reader :album, :photo, :tag
|
11
|
-
#
|
12
|
-
# Parse response from Fotki.oauth
|
13
|
-
#
|
14
|
-
# @param [RestClient::Response] response
|
15
|
-
#
|
16
|
-
def initialize(response)
|
17
|
-
# Nokogiri::XML(me).xpath("/app:service/app:workspace/app:collection[@id='album-list']/@href").text
|
18
|
-
collention = Fotki.xml_to_hash(response)['service']['workspace']['collection'].map{ |i| { i['id'] => i['href'] }}.inject(:merge)
|
19
|
-
@album = collention['album-list']
|
20
|
-
@photo = collention['photo-list']
|
21
|
-
@tag = collention['tag-list']
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Yandex
|
2
|
-
module API
|
3
|
-
module Fotki
|
4
|
-
#
|
5
|
-
# Class Photo is wrapper for single photo
|
6
|
-
#
|
7
|
-
# @see https://tech.yandex.ru/fotki/doc/operations-ref/photo-get-docpage/
|
8
|
-
#
|
9
|
-
class Photo
|
10
|
-
attr_reader :id, :links
|
11
|
-
#
|
12
|
-
# Photo initialize
|
13
|
-
#
|
14
|
-
# @param [RestClient::Response] response
|
15
|
-
#
|
16
|
-
def initialize(response)
|
17
|
-
entry = Fotki.xml_to_hash(response)['entry']
|
18
|
-
@id = entry['id'].split(':').last.to_i
|
19
|
-
@links = entry['img'].map{ |i| { i['size'] => i } }.inject(:merge)
|
20
|
-
# puts JSON.pretty_generate(entry)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module Yandex
|
2
|
-
module API
|
3
|
-
module Fotki
|
4
|
-
class Photos
|
5
|
-
#
|
6
|
-
# Uploading photo
|
7
|
-
#
|
8
|
-
# @param [Hash] options
|
9
|
-
#
|
10
|
-
# == Required
|
11
|
-
# @option options [File] :image IO stream of file. For example +File.new('tmp/file.png')+ or +open('\h\ttp://site.com/image.png')+
|
12
|
-
# == Optional
|
13
|
-
# @option options [String] :title Title of image
|
14
|
-
# @option options [String] :summary Description of image
|
15
|
-
# @option options [Integer] :album Id of album to upload
|
16
|
-
# @option options [String] :access public, friends or private
|
17
|
-
# @see https://tech.yandex.ru/fotki/doc/concepts/add-photo-docpage/#multipart-format
|
18
|
-
#
|
19
|
-
# @return [Fotki::Photo] Instance of Photo class
|
20
|
-
#
|
21
|
-
def self.upload(options)
|
22
|
-
raise Fotki::RuntimeError, ':image is required' unless options[:image]
|
23
|
-
response = RestClient.post(Fotki.api_urls.photo, options, Fotki.oauth_hash)
|
24
|
-
Photo.new(response)
|
25
|
-
end
|
26
|
-
#
|
27
|
-
# Get info about photo
|
28
|
-
#
|
29
|
-
# @param [Hash] options
|
30
|
-
#
|
31
|
-
# == Required
|
32
|
-
# @option options [String] :user Owner of photo
|
33
|
-
# @option options [String] :id Photo id
|
34
|
-
#
|
35
|
-
# @return [Fotki::Photo] Instance of Photo class
|
36
|
-
#
|
37
|
-
def self.get(options)
|
38
|
-
raise Fotki::RuntimeError, ':user is required' unless options[:user]
|
39
|
-
raise Fotki::RuntimeError, ':id is required' unless options[:id]
|
40
|
-
url = "#{API_HOST}/api/users/#{options[:user]}/photo/#{options[:id].to_s}/"
|
41
|
-
headers = options.except(:user, :id).merge(Fotki.oauth_hash)
|
42
|
-
response = RestClient.get(url, headers)
|
43
|
-
Photo.new(response)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|