shutterstock 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shutterstock.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Erick Schmitt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # Shutterstock
2
+
3
+ A gem for interfacing with the shutterstock API. See the documentation
4
+ for more info http://api.shutterstock.com/
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'shutterstock'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install shutterstock
19
+
20
+ ## Usage
21
+
22
+ Add your config settings to an initializer, such as
23
+ config/initializers/shutterstock.rb
24
+
25
+ ```ruby
26
+ Shutterstock.configure do |config|
27
+ config.username = 'xxx'
28
+ config.password = 'xxx'
29
+ end
30
+ ```
31
+
32
+ Currently this gem only supports searching for images. Usage:
33
+
34
+ ```ruby
35
+ client = Shutterstock::Client.new
36
+ trees = client.search('tree')
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ require "shutterstock/version"
2
+ require "shutterstock/configurable"
3
+ require "shutterstock/client"
4
+
5
+ module Shutterstock
6
+ class << self
7
+ include Shutterstock::Configurable
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require 'shutterstock/api/util'
2
+ module Shutterstock
3
+ module API
4
+ module Images
5
+ include Shutterstock::API::Util
6
+
7
+ BASE_PATH = 'images'
8
+
9
+ def search(searchterm, options = {})
10
+ call([BASE_PATH, 'search'], :get, {searchterm: searchterm}.merge(options))
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ module Shutterstock
2
+ module API
3
+ module Util
4
+ include Shutterstock::Configurable
5
+
6
+ FORMAT = :json
7
+ ENDPOINT = 'http://api.shutterstock.com'
8
+
9
+ def call(path, type, params = {})
10
+ base_url = "#{ File.join(ENDPOINT, path) }.#{ FORMAT }"
11
+
12
+ uri = URI.parse(base_url)
13
+ uri.query = URI.encode_www_form(params)
14
+
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])
18
+ response = http.request(request)
19
+ JSON.parse(response.body)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require 'shutterstock/api/util'
2
+ require 'shutterstock/api/images'
3
+
4
+ module Shutterstock
5
+ class Client
6
+ include Shutterstock::Configurable
7
+ include Shutterstock::API::Images
8
+
9
+ def initialize(options={})
10
+ Shutterstock::Configurable.keys.each do |key|
11
+ instance_variable_set(:"@#{key}", options[key] || Shutterstock.instance_variable_get(:"@#{key}"))
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ module Shutterstock
2
+ module Configurable
3
+ attr_writer :username, :password
4
+
5
+ class << self
6
+ def keys
7
+ @keys ||= [
8
+ :username,
9
+ :password
10
+ ]
11
+ end
12
+ end
13
+
14
+ def configure
15
+ yield self
16
+ self
17
+ end
18
+
19
+ def credentials
20
+ {
21
+ username: @username,
22
+ password: @password
23
+ }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Shutterstock
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'shutterstock/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "shutterstock"
8
+ gem.version = Shutterstock::VERSION
9
+ gem.authors = ["Erick Schmitt"]
10
+ gem.email = ["ejschmitt@gmail.com"]
11
+ gem.description = %q{A gem for interfacing with the shutterstock API}
12
+ gem.summary = %q{Shutterstock API gem}
13
+ gem.homepage = "https://github.com/ejschmitt/shutterstock"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shutterstock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Erick Schmitt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A gem for interfacing with the shutterstock API
15
+ email:
16
+ - ejschmitt@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/shutterstock.rb
27
+ - lib/shutterstock/api/images.rb
28
+ - lib/shutterstock/api/util.rb
29
+ - lib/shutterstock/client.rb
30
+ - lib/shutterstock/configurable.rb
31
+ - lib/shutterstock/version.rb
32
+ - shutterstock.gemspec
33
+ homepage: https://github.com/ejschmitt/shutterstock
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.24
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Shutterstock API gem
57
+ test_files: []