shutterstock 0.0.1 → 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: c4c09e3a51c93922dc7c495ae1eba0fa59541e18
4
+ data.tar.gz: 47e487f2a6f10be24ea4f6411946f782edfea73f
5
+ SHA512:
6
+ metadata.gz: f9ad93bc57e98edf16376926752d06816508d24c1d999e8c1261ed962047d32f768b62bc6ecdb030c782cf81f2c7fa3ede190da847f7b5e129286534693d5559
7
+ data.tar.gz: 617ee12fbde3f0f1be5a8b1a3dbe91c8e8fc9b9a5f3a3465c740b98f897eb25304d0b40a8bf56ab1b9c5d7dc80582a4af93f64776e9d53db7015a7987d7aaac1
data/README.md CHANGED
@@ -24,18 +24,45 @@ config/initializers/shutterstock.rb
24
24
 
25
25
  ```ruby
26
26
  Shutterstock.configure do |config|
27
+ config.api_username = 'xxx'
28
+ config.api_key = 'xxx'
27
29
  config.username = 'xxx'
28
30
  config.password = 'xxx'
31
+ config.email = 'xxx@yyy.zzz'
29
32
  end
30
33
  ```
31
34
 
32
- Currently this gem only supports searching for images. Usage:
35
+ Currently this gem only supports searching for images and
36
+ downloading/purchasing images.
37
+
38
+ Search usage:
33
39
 
34
40
  ```ruby
35
41
  client = Shutterstock::Client.new
36
42
  trees = client.search('tree')
37
43
  ```
38
44
 
45
+ Download/purchase usage:
46
+
47
+ ```ruby
48
+ client = Shutterstock::Client.new
49
+ trees = client.subscriptions(subscription_id, image_id, size, format)
50
+ ```
51
+
52
+ For size, you can use `Shutterstock::API::Subscriptions::SIZE.small`
53
+ (`medium`, `large`, and `vector` are other options)
54
+
55
+ For format, you can use `Shutterstock::API::Subscriptions::FORMAT.jpg`
56
+ (`eps` is the other option)
57
+
58
+ If there are additional query parameters you'd like to send to the API,
59
+ send an optional hash paramater to the methods. For example:
60
+
61
+ ```ruby
62
+ options = {search_group: "photos"}
63
+ trees = client.search('tree', options)
64
+ ```
65
+
39
66
  ## Contributing
40
67
 
41
68
  1. Fork it
@@ -0,0 +1,16 @@
1
+ require 'shutterstock/api/util'
2
+ module Shutterstock
3
+ module API
4
+ module Auth
5
+ include Shutterstock::API::Util
6
+ include Shutterstock::Configurable
7
+
8
+ BASE_PATH = 'auth'
9
+
10
+ def customer(options = {})
11
+ call([BASE_PATH, 'customer'], :post, {username: credentials[:username], password: credentials[:password]}.merge(options))
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ require 'shutterstock/api/util'
2
+ module Shutterstock
3
+ module API
4
+ module Subscriptions
5
+ include Shutterstock::API::Util
6
+
7
+ SIZE = OpenStruct.new({
8
+ small: "small",
9
+ medium: "medium",
10
+ huge: "huge",
11
+ vector: "vector"
12
+ })
13
+
14
+ FORMAT = OpenStruct.new({
15
+ jpg: "jpg",
16
+ eps: "eps"
17
+ })
18
+
19
+ def subscriptions(subscription_id, image_id, size, format, options = {})
20
+ unless subscription_id.nil? || image_id.nil? || size.nil? || format.nil?
21
+ call_with_auth_token(['subscriptions', subscription_id, "images", image_id, "sizes", size], :post, {format: format}.merge(options))
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -13,11 +13,21 @@ module Shutterstock
13
13
  uri.query = URI.encode_www_form(params)
14
14
 
15
15
  http = Net::HTTP.new(uri.host, uri.port)
16
- request = Net::HTTP::Get.new(uri.request_uri)
17
- request.basic_auth(credentials[:username], credentials[:password])
16
+ case type
17
+ when :get
18
+ request = Net::HTTP::Get.new(uri.request_uri)
19
+ when :post
20
+ request = Net::HTTP::Post.new(uri.request_uri)
21
+ end
22
+ request.basic_auth(credentials[:api_username], credentials[:api_key])
18
23
  response = http.request(request)
19
24
  JSON.parse(response.body)
20
25
  end
26
+
27
+ def call_with_auth_token(path, type, params = {})
28
+ call(path, type, {auth_token: customer["auth_token"]}.merge(params))
29
+ end
30
+
21
31
  end
22
32
  end
23
33
  end
@@ -1,10 +1,14 @@
1
1
  require 'shutterstock/api/util'
2
2
  require 'shutterstock/api/images'
3
+ require 'shutterstock/api/subscriptions'
4
+ require 'shutterstock/api/auth'
3
5
 
4
6
  module Shutterstock
5
7
  class Client
6
8
  include Shutterstock::Configurable
7
9
  include Shutterstock::API::Images
10
+ include Shutterstock::API::Subscriptions
11
+ include Shutterstock::API::Auth
8
12
 
9
13
  def initialize(options={})
10
14
  Shutterstock::Configurable.keys.each do |key|
@@ -1,12 +1,15 @@
1
1
  module Shutterstock
2
2
  module Configurable
3
- attr_writer :username, :password
3
+ attr_writer :api_username, :api_key, :username, :password, :email
4
4
 
5
5
  class << self
6
6
  def keys
7
7
  @keys ||= [
8
+ :api_username,
9
+ :api_key,
8
10
  :username,
9
- :password
11
+ :password,
12
+ :email
10
13
  ]
11
14
  end
12
15
  end
@@ -18,8 +21,11 @@ module Shutterstock
18
21
 
19
22
  def credentials
20
23
  {
24
+ api_username: @api_username,
25
+ api_key: @api_key,
21
26
  username: @username,
22
- password: @password
27
+ password: @password,
28
+ email: @email
23
29
  }
24
30
  end
25
31
  end
@@ -1,3 +1,3 @@
1
1
  module Shutterstock
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shutterstock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Erick Schmitt
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-04-09 00:00:00.000000000 Z
11
+ date: 2013-12-11 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A gem for interfacing with the shutterstock API
15
14
  email:
@@ -24,7 +23,9 @@ files:
24
23
  - README.md
25
24
  - Rakefile
26
25
  - lib/shutterstock.rb
26
+ - lib/shutterstock/api/auth.rb
27
27
  - lib/shutterstock/api/images.rb
28
+ - lib/shutterstock/api/subscriptions.rb
28
29
  - lib/shutterstock/api/util.rb
29
30
  - lib/shutterstock/client.rb
30
31
  - lib/shutterstock/configurable.rb
@@ -32,26 +33,25 @@ files:
32
33
  - shutterstock.gemspec
33
34
  homepage: https://github.com/ejschmitt/shutterstock
34
35
  licenses: []
36
+ metadata: {}
35
37
  post_install_message:
36
38
  rdoc_options: []
37
39
  require_paths:
38
40
  - lib
39
41
  required_ruby_version: !ruby/object:Gem::Requirement
40
- none: false
41
42
  requirements:
42
- - - ! '>='
43
+ - - '>='
43
44
  - !ruby/object:Gem::Version
44
45
  version: '0'
45
46
  required_rubygems_version: !ruby/object:Gem::Requirement
46
- none: false
47
47
  requirements:
48
- - - ! '>='
48
+ - - '>='
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
52
  rubyforge_project:
53
- rubygems_version: 1.8.24
53
+ rubygems_version: 2.0.3
54
54
  signing_key:
55
- specification_version: 3
55
+ specification_version: 4
56
56
  summary: Shutterstock API gem
57
57
  test_files: []