yandex-api-fotki 0.1.9 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7fa951b52c92886ef597d9618a778a833311ad1
4
- data.tar.gz: 653fa71a2011ba83b3f8c45830cd67fbca4da880
3
+ metadata.gz: 474d696beaa797f90dbb3f88ecc3fce68a4f5d0b
4
+ data.tar.gz: 0ab018f05997e946e525dcc0065755c7cb4a5b23
5
5
  SHA512:
6
- metadata.gz: 96b378e80c898c09d2ce4ff8207124315dabb80d6b9554df531bdd7d3ecf160d96e3ca6e373298f93b1be986e166f24af24ece3b8b3435b071d35fe382971a1d
7
- data.tar.gz: c3324548a71805ead2b1289b3c1889083e42ad347f692d9040274cfa7e4317c0bc1afc0b88f21ec3c7e3f89f968224df235ea40a2ab76d56d013e44540fc4f8e
6
+ metadata.gz: d2452e808240219bbf1c224c51d5264d4d96a87b3e45b68d75c813f930908a607126783f01c099e0e9ab1ce3ac3dd27d5db9d8d1aac0d7fca2616a040632c835
7
+ data.tar.gz: 85fde0ede6a15ab7a29f02668112db60e8702c6419189a571904ad77b549bb5c4b50a0d7846e9c91aec5200ddb14e29a6e2655fd576b54afb1f86a3bd9dfca1d
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Yandex::Api::Fotki
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/yandex-api-fotki.svg)](https://rubygems.org/gems/yandex-api-fotki)
4
- [![Build Status](https://travis-ci.org/1v/yandex-api-fotki.svg?branch=master)](https://travis-ci.org/1v/yandex-api-fotki)
4
+ [![Build Status](https://travis-ci.org/1v/yandex-api-fotki.svg?branch=0.1)](https://travis-ci.org/1v/yandex-api-fotki)
5
5
  [![Dependency Status](https://gemnasium.com/badges/github.com/1v/yandex-api-fotki.svg)](https://gemnasium.com/github.com/1v/yandex-api-fotki)
6
6
  [![Code Climate](https://codeclimate.com/github/1v/yandex-api-fotki/badges/gpa.svg)](https://codeclimate.com/github/1v/yandex-api-fotki)
7
7
  [![Test Coverage](https://codeclimate.com/github/1v/yandex-api-fotki/badges/coverage.svg)](https://codeclimate.com/github/1v/yandex-api-fotki/coverage)
@@ -17,7 +17,12 @@ API wrapper for Yandex Fotki
17
17
  Add this line to your application's Gemfile:
18
18
 
19
19
  ```ruby
20
- gem 'yandex-api-fotki'
20
+ # for ruby >= 2.2.2
21
+ gem 'yandex-api-fotki', '~> 1.0', '>= 1.0.0'
22
+ ```
23
+ ```ruby
24
+ # for ruby < 2.2.2
25
+ gem 'yandex-api-fotki', '~> 0.1', '>= 0.1.8'
21
26
  ```
22
27
 
23
28
  And then execute:
@@ -25,8 +30,14 @@ And then execute:
25
30
  $ bundle
26
31
 
27
32
  Or install it yourself as:
28
-
29
- $ gem install yandex-api-fotki
33
+ ```bash
34
+ # for ruby >= 2.2.2
35
+ $ gem install yandex-api-fotki -v '~> 1.0'
36
+ ```
37
+ ```bash
38
+ # for ruby < 2.2.2
39
+ $ gem install yandex-api-fotki -v '~> 0.1'
40
+ ```
30
41
 
31
42
  And require:
32
43
  ```ruby
@@ -37,10 +48,10 @@ require 'yandex-api-fotki'
37
48
  Instruction how to get OAUTH_CODE [`tech.yandex.ru`](https://tech.yandex.ru/oauth/doc/dg/tasks/get-oauth-token-docpage/)
38
49
  ```ruby
39
50
  fotki = Yandex::API::Fotki.oauth(OAUTH_CODE)
40
- photo = fotki.photos.upload(:image => File.new('/file.png'),
41
- :access => 'private',
42
- :album => 123456,
43
- :title => "My Image")
51
+ photo = fotki.photos.upload(image: File.new('/file.png'),
52
+ access: 'private',
53
+ album: 123456,
54
+ title: 'My Image')
44
55
  photo.id
45
56
  => 123456
46
57
  photo.links
@@ -1,11 +1,17 @@
1
1
  require 'rest-client'
2
2
  require 'active_support/core_ext/hash/conversions'
3
3
 
4
- require 'yandex/api/fotki/version'
4
+ require_relative 'fotki/version'
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'
5
10
 
6
11
  module Yandex
7
12
  module API
8
13
  module Fotki
14
+ API_HOST = 'http://api-fotki.yandex.ru'
9
15
  class RuntimeError < RuntimeError ; end
10
16
  #
11
17
  # Main method for authentification
@@ -16,9 +22,9 @@ module Yandex
16
22
  # @see https://tech.yandex.ru/oauth/doc/dg/reference/web-client-docpage/
17
23
  #
18
24
  def self.oauth(oauth_code)
19
- return self unless @api_urls.nil?
25
+ return self if !@api_urls.nil? && @oauth_code === oauth_code
20
26
  @oauth_code = oauth_code
21
- me = RestClient.get('http://api-fotki.yandex.ru/api/me/',
27
+ me = RestClient.get("#{API_HOST}/api/me/",
22
28
  Fotki.oauth_hash)
23
29
  @api_urls = Me.new(me)
24
30
  self
@@ -66,126 +72,6 @@ module Yandex
66
72
  Photos
67
73
  end
68
74
  #
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
- #
189
75
  # XML parser wrapper. Because I'm not sure if it be persistent.
190
76
  #
191
77
  # @param [String] xml XML input
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,36 @@
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
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,25 @@
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
@@ -0,0 +1,48 @@
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
@@ -1,7 +1,7 @@
1
1
  module Yandex
2
2
  module API
3
3
  module Fotki
4
- VERSION = '0.1.9'
4
+ VERSION = '0.2.0'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yandex-api-fotki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.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-09 00:00:00.000000000 Z
11
+ date: 2016-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -128,6 +128,11 @@ 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
131
136
  - lib/yandex/api/fotki/version.rb
132
137
  - yandex-api-fotki.gemspec
133
138
  homepage: https://github.com/1v/yandex-api-fotki