photozou 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5669569e82b08ff9e888e6b63defa96ec6e3bc72
4
+ data.tar.gz: 2a9f7df0cfea2da7de8124e22cd2f14ec0860199
5
+ SHA512:
6
+ metadata.gz: 3814f844acb30bfaf7f6f96cd8235e8d3a8d8db041e05abb03348f92e41adb36b09d503812373dddffbe69f16d4ea2d3b691a45d9711f9bd3dde280d90cdab90
7
+ data.tar.gz: 97966f862f42df0b0624058826ea49ef9b8ce2da895718e2d6e61b2fa34800bb7f3402baf65269dcf6b52a2b6e77fe5bccd475f0ed2daec687e2930f80a0943a
@@ -0,0 +1,4 @@
1
+ /Gemfile.lock
2
+ /doc/
3
+ /pkg/
4
+ /examples/credential.json
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 ser1zw
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Photozou Ruby Gem
2
+
3
+ A Ruby interface to the [Photozou](http://photozou.jp/) API.
4
+
5
+ [Photozou API](http://photozou.jp/basic/api)
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ $ gem install photozou
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ See examples folder.
16
+
17
+
18
+ ## API Coverage
19
+
20
+ |API|Status|
21
+ |---|---|
22
+ |nop|Done|
23
+ |photo_add|Done|
24
+ |photo_add_album||
25
+ |photo_add_favorite||
26
+ |photo_add_tag||
27
+ |photo_album|Done|
28
+ |photo_album_photo|Done|
29
+ |photo_comment||
30
+ |photo_delete|Done|
31
+ |photo_delete_favorite||
32
+ |photo_edit_album||
33
+ |photo_get_favorite||
34
+ |photo_info|Done|
35
+ |photo_list_public||
36
+ |search_public||
37
+ |user_group||
38
+ |user_info|Done|
39
+
40
+
41
+ ## License
42
+
43
+ [MIT License](http://opensource.org/licenses/MIT)
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
Binary file
@@ -0,0 +1 @@
1
+ { "user_id": "foo@example.com", "password": "bar" }
@@ -0,0 +1,7 @@
1
+ require 'photozou'
2
+
3
+ c = JSON.load(open(File.dirname(__FILE__) + '/credential.json', 'r'))
4
+ client = Photozou::Client.new(c['user_id'], c['password'])
5
+
6
+ ret = client.nop
7
+ puts "user_id = #{ret.user_id}"
@@ -0,0 +1,19 @@
1
+ require 'photozou'
2
+
3
+ c = JSON.load(open(File.dirname(__FILE__) + '/credential.json', 'r'))
4
+ client = Photozou::Client.new(c['user_id'], c['password'])
5
+
6
+ image = open(File.dirname(__FILE__) + '/Lenna.png', 'r')
7
+
8
+ # Get albums
9
+ albums = client.photo_album
10
+ album_id = albums[0].album_id
11
+
12
+ # Post image to album
13
+ res = client.photo_add(album_id, image, 'image/png',
14
+ { photo_title: 'Lenna',
15
+ description: 'Lenna or Lena is the name given to a standard test image widely used in the field of image processing since 1973.',
16
+ tag: 'Lenna Lena' })
17
+
18
+ puts "photo_id = #{res['photo_id']}"
19
+ puts "url = #{res['url']}"
@@ -0,0 +1,10 @@
1
+ require 'photozou'
2
+
3
+ c = JSON.load(open(File.dirname(__FILE__) + '/credential.json', 'r'))
4
+ client = Photozou::Client.new(c['user_id'], c['password'])
5
+
6
+ # Get albums
7
+ albums = client.photo_album
8
+ albums.each { |album|
9
+ puts "#{album.album_id}\t#{album.name}\t#{album.created_time}"
10
+ }
@@ -0,0 +1,13 @@
1
+ require 'photozou'
2
+
3
+ c = JSON.load(open(File.dirname(__FILE__) + '/credential.json', 'r'))
4
+ client = Photozou::Client.new(c['user_id'], c['password'])
5
+
6
+ # Get albums
7
+ albums = client.photo_album
8
+ album_id = albums[0].album_id
9
+
10
+ photos = client.photo_album_photo(album_id)
11
+ photos.each { |photo|
12
+ puts "#{photo.photo_id}\t#{photo.photo_title}\t[#{photo.tags.join(', ')}]\t#{photo.image_url}\t#{photo.original_image_url}"
13
+ }
@@ -0,0 +1,16 @@
1
+ require 'photozou'
2
+
3
+ c = JSON.load(open(File.dirname(__FILE__) + '/credential.json', 'r'))
4
+ client = Photozou::Client.new(c['user_id'], c['password'])
5
+
6
+ # Get albums
7
+ albums = client.photo_album
8
+ album_id = albums[0].album_id
9
+
10
+ # Get photos
11
+ photos = client.photo_album_photo(album_id)
12
+
13
+ # Delete all photos
14
+ photos.each { |photo|
15
+ client.photo_delete(photo.photo_id)
16
+ }
@@ -0,0 +1,24 @@
1
+ require 'photozou'
2
+
3
+ c = JSON.load(open(File.dirname(__FILE__) + '/credential.json', 'r'))
4
+ client = Photozou::Client.new(c['user_id'], c['password'])
5
+
6
+ # Get albums
7
+ albums = client.photo_album
8
+ album_id = albums[0].album_id
9
+
10
+ # Get photos in the album
11
+ photos = client.photo_album_photo(album_id)
12
+
13
+ photo_id = photos[0].photo_id
14
+
15
+ photo = client.photo_info(photo_id)
16
+
17
+ puts "photo_id = #{photo.photo_id}"
18
+ puts "photo_title = #{photo.photo_title}"
19
+ puts "description = #{photo.description}"
20
+ puts "size = #{photo.original_width}x#{photo.original_height}"
21
+ puts "url = #{photo.url}"
22
+ puts "image_url = #{photo.image_url}"
23
+ puts "original_image_url = #{photo.original_image_url}"
24
+ puts "tags = [#{photo.tags.join(', ')}]"
@@ -0,0 +1,15 @@
1
+ require 'photozou'
2
+
3
+ c = JSON.load(open(File.dirname(__FILE__) + '/credential.json', 'r'))
4
+ client = Photozou::Client.new(c['user_id'], c['password'])
5
+
6
+ # Get user_id
7
+ res = client.nop
8
+
9
+ # Get user information
10
+ user = Photozou::Client.user_info(res.user_id)
11
+
12
+ puts "user_id = #{user.user_id}"
13
+ puts "nick_name = #{user.nick_name}"
14
+ puts "photo_num = #{user.photo_num}"
15
+ puts "profile_url = #{user.profile_url}"
@@ -0,0 +1,2 @@
1
+ require 'photozou/version'
2
+ require 'photozou/client'
@@ -0,0 +1,14 @@
1
+ require 'date'
2
+ require 'photozou/base'
3
+
4
+ module Photozou
5
+ class Album < Base
6
+ def initialize(attrs)
7
+ super attrs
8
+
9
+ ['created_time', 'updated_time'].each { |m|
10
+ override(m) { |a| DateTime.parse(a) }
11
+ }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ require 'photozou/utils'
2
+ require 'photozou/album'
3
+
4
+ module Photozou
5
+ module Api
6
+ module Album
7
+ include Photozou::Utils
8
+
9
+ # http://photozou.jp/basic/api_method_photo_album
10
+ def photo_album
11
+ albums = []
12
+ res = get_json_with_credential('/photo_album.json')
13
+ res['info']['album'].each { |album| albums << Photozou::Album.new(album) } if res['info']['album']
14
+ albums
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ require 'photozou/utils'
2
+
3
+ module Photozou
4
+ module Api
5
+ module Nop
6
+ include Photozou::Utils
7
+
8
+ # http://photozou.jp/basic/api_method_nop
9
+ def nop
10
+ res = get_json_with_credential('/nop.json')
11
+ Photozou::Info.new(res['info'])
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,38 @@
1
+ require 'photozou/utils'
2
+ require 'photozou/photo'
3
+
4
+ module Photozou
5
+ module Api
6
+ module Photo
7
+ include Photozou::Utils
8
+
9
+ # http://photozou.jp/basic/api_method_photo_info
10
+ def photo_info(photo_id, option = { private: true })
11
+ option['photo_id'] = photo_id
12
+ res = get_json_with_credential('/photo_info.json', option)
13
+ Photozou::Photo.new(res['info']['photo'])
14
+ end
15
+
16
+ # http://photozou.jp/basic/api_method_photo_album_photo
17
+ def photo_album_photo(album_id, option = {})
18
+ option['album_id'] = album_id
19
+ res = get_json_with_credential('/photo_album_photo.json', option)
20
+ photos = res['info']['photo'] || []
21
+
22
+ photos.map { |photo| Photozou::Photo.new(photo) }
23
+ end
24
+
25
+ # http://photozou.jp/basic/api_method_photo_add
26
+ def photo_add(album_id, photo, content_type, option = {})
27
+ option['album_id'] = album_id
28
+ option['photo'] = [ photo, { 'Content-Type': content_type } ]
29
+ res = post_multipart_with_credential('/photo_add.json', option)
30
+ end
31
+
32
+ # http://photozou.jp/basic/api_method_photo_delete
33
+ def photo_delete(photo_id)
34
+ res = post_with_credential('/photo_delete.json', { 'photo_id': photo_id })
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ require 'photozou/utils'
2
+ require 'photozou/user'
3
+
4
+ module Photozou
5
+ module Api
6
+ module User
7
+ include Photozou::Utils
8
+
9
+ # http://photozou.jp/basic/api_method_user_info
10
+ def self.user_info(user_id)
11
+ res = Utils.get_json('/user_info.json', { user_id: user_id })
12
+ Photozou::User.new(res['info']['user'])
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module Photozou
2
+ class Base
3
+ def initialize(attrs = {})
4
+ @attrs = attrs || {}
5
+ @attrs.keys.each { |key|
6
+ self.class.send(:define_method, key) {
7
+ @attrs[key]
8
+ }
9
+ }
10
+ end
11
+
12
+ def override(attr_name, &block)
13
+ @attrs[attr_name] = block.call(@attrs[attr_name])
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ require 'photozou/api/nop'
6
+ require 'photozou/api/album'
7
+ require 'photozou/api/photo'
8
+ require 'photozou/api/user'
9
+
10
+ require 'photozou/utils'
11
+ require 'photozou/info'
12
+ require 'photozou/album'
13
+ require 'photozou/photo'
14
+ require 'photozou/user'
15
+ require 'photozou/error'
16
+
17
+ module Photozou
18
+ class Client
19
+ include Photozou::Api::Nop
20
+ include Photozou::Api::Album
21
+ include Photozou::Api::Photo
22
+ include Photozou::Api::User
23
+
24
+ attr_reader :login_id, :password
25
+
26
+ def initialize(login_id, password)
27
+ @login_id = login_id
28
+ @password = password
29
+ end
30
+
31
+ # http://photozou.jp/basic/api_method_user_info
32
+ def self.user_info(user_id)
33
+ Photozou::Api::User.user_info(user_id)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ module Photozou
2
+ class Error < StandardError
3
+ attr_reader :code, :message
4
+
5
+ def initialize(code, message)
6
+ @code = code
7
+ @message = message
8
+ end
9
+
10
+ def to_s
11
+ "#{@code}: #{message}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ require 'photozou/base'
2
+
3
+ module Photozou
4
+ class Info < Base
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ require 'date'
2
+ require 'photozou/base'
3
+
4
+ module Photozou
5
+ class Photo < Base
6
+ def initialize(attrs)
7
+ super attrs
8
+
9
+ override('date') { |a| a && Date.parse(a) }
10
+ override('regist_time') { |a| DateTime.parse(a) }
11
+ override('geo') { |a| a && Geo.new(a) }
12
+ end
13
+
14
+ class Geo < Base
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ require 'photozou/base'
2
+
3
+ module Photozou
4
+ class User < Base
5
+ end
6
+ end
@@ -0,0 +1,86 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ require 'photozou/error'
6
+
7
+ module Photozou
8
+ module Utils
9
+ REST_URL = 'https://api.photozou.jp/rest'
10
+
11
+ module_function
12
+
13
+ def get_json(path, option = {}, credentials = {})
14
+ uri = URI.parse(REST_URL + path)
15
+ uri.query = URI.encode_www_form(option) if option.size > 0
16
+
17
+ request = Net::HTTP::Get.new(uri)
18
+ request.basic_auth(credentials[:login_id], credentials[:password]) if credentials.size > 0
19
+
20
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) { |http|
21
+ http.request(request)
22
+ }
23
+
24
+ json = JSON.parse(response.body)
25
+ if json['stat'] == 'fail'
26
+ error = json['err'].first # FIXME: API may return multiple errors, but only 1 error is supported for now
27
+ raise Photozou::Error.new(error['code'], error['msg'])
28
+ end
29
+
30
+ json
31
+ end
32
+
33
+ def post(path, data = {}, credentials = {})
34
+ uri = URI.parse(REST_URL + path)
35
+
36
+ request = Net::HTTP::Post.new(uri)
37
+ request.set_form_data(data)
38
+ request.basic_auth(credentials[:login_id], credentials[:password]) if credentials.size > 0
39
+
40
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) { |http|
41
+ http.request(request)
42
+ }
43
+
44
+ json = JSON.parse(response.body)
45
+ if json['stat'] == 'fail'
46
+ error = json['err'].first # FIXME: API may return multiple errors, but only 1 error is supported for now
47
+ raise Photozou::Error.new(error['code'], error['msg'])
48
+ end
49
+
50
+ json
51
+ end
52
+
53
+ def post_multipart(path, data = {}, credentials = {})
54
+ uri = URI.parse(REST_URL + path)
55
+
56
+ request = Net::HTTP::Post.new(uri)
57
+ data = data.map { |k, v| [k.to_s, v].flatten }
58
+ request.set_form(data, 'multipart/form-data')
59
+ request.basic_auth(credentials[:login_id], credentials[:password]) if credentials.size > 0
60
+
61
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) { |http|
62
+ http.request(request)
63
+ }
64
+
65
+ json = JSON.parse(response.body)
66
+ if json['stat'] == 'fail'
67
+ error = json['err'].first # FIXME: API may return multiple errors, but only 1 error is supported for now
68
+ raise Photozou::Error.new(error['code'], error['msg'])
69
+ end
70
+
71
+ json
72
+ end
73
+
74
+ def get_json_with_credential(path, option = {})
75
+ Utils.get_json(path, option, { login_id: @login_id, password: @password })
76
+ end
77
+
78
+ def post_multipart_with_credential(path, form_data = {})
79
+ Utils.post_multipart(path, form_data, { login_id: @login_id, password: @password })
80
+ end
81
+
82
+ def post_with_credential(path, form_data = {})
83
+ Utils.post(path, form_data, { login_id: @login_id, password: @password })
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module Photozou
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'photozou/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'photozou'
8
+ spec.version = Photozou::VERSION
9
+ spec.authors = ['ser1zw']
10
+ spec.email = ['azariahsawtikes@gmail.com']
11
+
12
+ spec.summary = 'A Ruby interface to the Photozou (http://photozou.jp/) API'
13
+ spec.homepage = 'https://github.com/ser1zw/photozou'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.15'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: photozou
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ser1zw
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - azariahsawtikes@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - examples/Lenna.png
54
+ - examples/credential.json.sample
55
+ - examples/nop.rb
56
+ - examples/photo_add.rb
57
+ - examples/photo_album.rb
58
+ - examples/photo_album_photo.rb
59
+ - examples/photo_delete.rb
60
+ - examples/photo_info.rb
61
+ - examples/user_info.rb
62
+ - lib/photozou.rb
63
+ - lib/photozou/album.rb
64
+ - lib/photozou/api/album.rb
65
+ - lib/photozou/api/nop.rb
66
+ - lib/photozou/api/photo.rb
67
+ - lib/photozou/api/user.rb
68
+ - lib/photozou/base.rb
69
+ - lib/photozou/client.rb
70
+ - lib/photozou/error.rb
71
+ - lib/photozou/info.rb
72
+ - lib/photozou/photo.rb
73
+ - lib/photozou/user.rb
74
+ - lib/photozou/utils.rb
75
+ - lib/photozou/version.rb
76
+ - photozou.gemspec
77
+ homepage: https://github.com/ser1zw/photozou
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.6.12
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: A Ruby interface to the Photozou (http://photozou.jp/) API
101
+ test_files: []