bigstock-client 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c96c21930404e63612b29c63fe70c30c0fccc494
4
+ data.tar.gz: 9679729e2a07638b2baf51329b64cb3561084856
5
+ SHA512:
6
+ metadata.gz: 93dfae45a0e096ed72193e13c084b2c1886426bf7d15b80d980396c4648fc64c6d3720c0f457d13ddd7b051c5616a104ab3fffdcb5f0774ec5d57723459374c2
7
+ data.tar.gz: be0f903fa18b6f6e0b4a41f4e0e8968885e378988a5cca42f5c281b3a54a1b59ab22f6e4dd29bbbde4cd7770f9b2175ca29a56aa50d9216277dbc0c94d0bbcea
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'json', '~>1.8'
4
+ gem 'httparty', '~>0.13'
5
+
@@ -0,0 +1,17 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ hashie (3.3.2)
5
+ httparty (0.13.3)
6
+ json (~> 1.8)
7
+ multi_xml (>= 0.5.2)
8
+ json (1.8.1)
9
+ multi_xml (0.5.5)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ hashie (~> 3.3)
16
+ httparty (~> 0.13)
17
+ json (~> 1.8)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 moiesk
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,90 @@
1
+ # bigstock-client-ruby
2
+
3
+ A Ruby client for Bigstock's API
4
+
5
+ ## Installation
6
+
7
+ Bigstock-Client-Ruby is available as a RubyGem:
8
+
9
+ ```bash
10
+ $ gem install bigstock-client
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Create an instance of the Bigstock API Client by passing in your API ID
16
+ and API Secret as parameters. The client will then handle any authentication
17
+ when required.
18
+
19
+ ```ruby
20
+ require 'bigstock/client'
21
+ client = Bigstock::Client::Client.new('API_ID', 'API_SECRET')
22
+ ```
23
+
24
+ Then use the client to contact the Bigstock-API
25
+
26
+ ### Search
27
+ ```ruby
28
+ response = client.search('dog')
29
+ if response['message'] == 'success'
30
+ pages = response['data']['pages']
31
+ images = response['data']['images']
32
+ end
33
+ ```
34
+
35
+ Additional options might be passed to the `search`. For a list of
36
+ options see [Bigstock's API
37
+ documentatation](http://help.bigstockphoto.com/hc/en-us/articles/200303245-API-Documentation#search)
38
+
39
+ For example, to get only the first five images for 'dog' but
40
+ with all image details:
41
+ ```ruby
42
+ response = client.search('dog', response_detail: 'all', limit: 5)
43
+ ```
44
+
45
+ ### Image Detail
46
+
47
+ The image ID returned in a search response can be used to query for more
48
+ information about a specific image.
49
+ ```ruby
50
+ response = client.image('IMAGE_ID')
51
+ if response['message'] == 'success'
52
+ image = response['data']['image']
53
+ end
54
+ ```
55
+
56
+ ### Purchase
57
+
58
+ Once you have funded your API account you will be able to download full
59
+ resolution un-watermarked images.
60
+ ```ruby
61
+ response = client.purchase('IMAGE_ID', 'SIZE_CODE')
62
+ if response['message'] == 'success'
63
+ download_url = client.get_download_url(response['data']['download_id'])
64
+ end
65
+ ```
66
+
67
+ ### Lightboxes & Saved Images
68
+
69
+ To get the list of private lightbox content saved under your account:
70
+
71
+ ```ruby
72
+ response = client.lightboxes
73
+ if response['message'] == 'success'
74
+ total_items = response['data']['total_items']
75
+ lightboxes = response['data']['lightboxes']
76
+ end
77
+ ```
78
+
79
+ To get the content of a lightbox
80
+
81
+ ```ruby
82
+ response = client.lightbox('LIGHTBOX_ID')
83
+ if response['message'] == 'success'
84
+ pages = response['data']['pages']
85
+ lightbox = response['data']['lightbox']
86
+ images = response['data']['images']
87
+ end
88
+ ```
89
+
90
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bigstock/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bigstock-client"
8
+ spec.version = Bigstock::Client::VERSION
9
+ spec.authors = ["Moises Eskinazi"]
10
+ spec.email = ["meskinazi@shutterstock.com"]
11
+ spec.summary = %q{A ruby client for Bigstock's API}
12
+ spec.description = %q{A simple ruby library to access Bigstock's API. Bigstock is an easy-to-use marketplace for stock images}
13
+ spec.homepage = "http://rubygems.org/gems/bigstock-client"
14
+ spec.license = "MIT"
15
+
16
+ # This will only work with ruby 2.1 or greater
17
+ spec.required_ruby_version = '~> 2.1'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,76 @@
1
+ require 'bigstock/client/version'
2
+ require 'httparty'
3
+ require 'json'
4
+ require 'digest/sha1'
5
+
6
+ module Bigstock
7
+ module Client
8
+ class Client
9
+ include HTTParty
10
+ format :json
11
+
12
+ API_VERSION = 2
13
+
14
+ def initialize(account_id, secret, use_ssl: false, use_test_api: false)
15
+ @account_id = account_id
16
+ @secret = secret
17
+ protocol = use_ssl ? 'https' : 'http'
18
+ subdomain = use_test_api ? 'testapi' : 'api'
19
+ self.class.base_uri "#{protocol}://#{subdomain}.bigstockphoto.com/#{API_VERSION}/#{@account_id}"
20
+ end
21
+
22
+ def search(query, options = {})
23
+ args = {query: {q: query}}
24
+ args[:query] = args[:query].merge(options) unless options.empty?
25
+ self.class.get('/search', args).parsed_response
26
+ end
27
+
28
+ def asset(asset_id, asset_type)
29
+ self.class.get("/#{asset_type}/#{asset_id}").parsed_response
30
+ end
31
+
32
+ def image(image_id)
33
+ asset(image_id, 'image')
34
+ end
35
+
36
+ def video(video_id)
37
+ asset(video_id, 'video')
38
+ end
39
+
40
+ def collections
41
+ self.class.get('/lightbox', query: { auth_key: get_auth }).parsed_response
42
+ end
43
+
44
+ def collection(collection_id)
45
+ self.class.get("/lightbox/#{collection_id}", query: { auth_key: get_auth(collection_id) }).parsed_response
46
+ end
47
+
48
+ alias_method :lightboxes, :collections
49
+
50
+ alias_method :lightbox, :collection
51
+
52
+ def purchase(asset_id, size_code)
53
+ self.class.get('/purchase', query: { image_id: asset_id, size_code: size_code, auth_key: get_auth(asset_id) }).parsed_response
54
+ end
55
+
56
+ def get_download_url(download_id)
57
+ [
58
+ self.class.base_uri,
59
+ '/download?',
60
+ "download_id=#{download_id}",
61
+ "&auth_key=#{get_auth(download_id)}"
62
+ ].join
63
+ end
64
+
65
+ private
66
+
67
+ def get_auth(additional_params = [])
68
+ elements = [@secret, @account_id].concat(Array(additional_params))
69
+ Digest::SHA1.hexdigest(elements.join)
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
@@ -0,0 +1,5 @@
1
+ module Bigstock
2
+ module Client
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bigstock-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Moises Eskinazi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-12 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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: A simple ruby library to access Bigstock's API. Bigstock is an easy-to-use
42
+ marketplace for stock images
43
+ email:
44
+ - meskinazi@shutterstock.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - bigstock-client.gemspec
56
+ - lib/bigstock/client.rb
57
+ - lib/bigstock/client/version.rb
58
+ homepage: http://rubygems.org/gems/bigstock-client
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: '2.1'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.2.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A ruby client for Bigstock's API
82
+ test_files: []