imagga-categorization 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.
- data/.gitignore +34 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +22 -0
- data/README.md +70 -0
- data/Rakefile +7 -0
- data/imagga-categorization.gemspec +25 -0
- data/imagga-categorization_spec.rb +0 -0
- data/lib/imagga/categorization.rb +9 -0
- data/lib/imagga/categorization/client.rb +47 -0
- data/lib/imagga/categorization/configuration.rb +37 -0
- data/lib/imagga/categorization/version.rb +5 -0
- data/spec/lib/client_spec.rb +98 -0
- data/spec/lib/configuration_spec.rb +33 -0
- data/spec/lib/imagga-categorization_spec.rb +12 -0
- data/spec/spec_helper.rb +1 -0
- metadata +115 -0
data/.gitignore
ADDED
@@ -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
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
imagga-categorization (0.0.1)
|
5
|
+
httparty
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.2.5)
|
11
|
+
httparty (0.13.0)
|
12
|
+
json (~> 1.8)
|
13
|
+
multi_xml (>= 0.5.2)
|
14
|
+
json (1.8.1)
|
15
|
+
multi_xml (0.5.5)
|
16
|
+
rake (10.2.1)
|
17
|
+
rspec (2.14.1)
|
18
|
+
rspec-core (~> 2.14.0)
|
19
|
+
rspec-expectations (~> 2.14.0)
|
20
|
+
rspec-mocks (~> 2.14.0)
|
21
|
+
rspec-core (2.14.8)
|
22
|
+
rspec-expectations (2.14.5)
|
23
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
24
|
+
rspec-mocks (2.14.6)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
imagga-categorization!
|
31
|
+
rake
|
32
|
+
rspec
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 synoptase
|
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,70 @@
|
|
1
|
+
# Imagga::Categorization
|
2
|
+
|
3
|
+
This gem is a simple wrapper around Imagga's categorization API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'imagga-categorization'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install imagga-categorization
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
**Create a client**
|
22
|
+
|
23
|
+
``` ruby
|
24
|
+
client = Imagga::Categorization::Client.new app_key: YOUR_API_KEY
|
25
|
+
```
|
26
|
+
|
27
|
+
**Consume an endpoint**
|
28
|
+
|
29
|
+
The gem currently supports 3 endpoints:
|
30
|
+
- `/draft/classify/{classifier_id}`
|
31
|
+
- `/draft/classify/result/{ticket_id}`
|
32
|
+
- `/draft/tasks/{task_id}`
|
33
|
+
|
34
|
+
A call to any of these endpoints needs an `api_key`:
|
35
|
+
> Before you begin you should [Request Your Free Trial](http://imagga.com/) from Imagga website in order to get an api_key. The api key is the only required authentication method currently and should be provided with every request as a parameter in the URL.
|
36
|
+
|
37
|
+
Imagga's full api documentation [can be found here](http://docs.imagga.apiary.io/#classification). It lists the possible parameters for each endpoint.
|
38
|
+
|
39
|
+
**Classify**
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
parameters = {
|
43
|
+
"async": "1",
|
44
|
+
"urls": "https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-prn2/969321_526818917353598_661738580_n.jpg, http://example.com/image2.jpg"
|
45
|
+
}
|
46
|
+
response = client.classify(YOUR_CLASSIFIER_ID, parameters)
|
47
|
+
```
|
48
|
+
|
49
|
+
**Classify result**
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
response = client.classify_result(ticket_id)
|
53
|
+
```
|
54
|
+
|
55
|
+
**Task result**
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
response = client.task_result(task_id)
|
59
|
+
```
|
60
|
+
|
61
|
+
## TODO
|
62
|
+
- Write some fracking unit tests
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
1. Fork it
|
67
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
68
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
69
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
70
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'imagga/categorization/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "imagga-categorization"
|
8
|
+
spec.version = Imagga::Categorization::VERSION
|
9
|
+
spec.authors = ["Benjamin Grelié"]
|
10
|
+
spec.email = ["benjamin@printicapp.com"]
|
11
|
+
spec.description = %q{Ruby client for accessing Imagga categorization & training API}
|
12
|
+
spec.summary = %q{Ruby client for accessing Imagga categorization & training API}
|
13
|
+
spec.homepage = "http://github.com/printic/imagga-categorization"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "httparty"
|
22
|
+
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
module Imagga
|
4
|
+
module Categorization
|
5
|
+
class Client
|
6
|
+
include HTTParty
|
7
|
+
|
8
|
+
# Define the same set of accessors as the Categorization module
|
9
|
+
attr_accessor *Configuration::VALID_CONFIG_KEYS
|
10
|
+
|
11
|
+
def initialize(options={})
|
12
|
+
# Merge the config values from the module and those passed
|
13
|
+
# to the client.
|
14
|
+
merged_options = Categorization.options.merge(options)
|
15
|
+
|
16
|
+
# Copy the merged values to this client and ignore those
|
17
|
+
# not part of our configuration
|
18
|
+
Configuration::VALID_CONFIG_KEYS.each do |key|
|
19
|
+
send("#{key}=", merged_options[key])
|
20
|
+
end
|
21
|
+
|
22
|
+
# set the endpoint for HTTParty
|
23
|
+
self.class.base_uri self.endpoint.to_s
|
24
|
+
|
25
|
+
# set a default api_key parameter for each HTTParty request
|
26
|
+
@options = {
|
27
|
+
query: { api_key: self.api_key }
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def classify(classifier_id, options={})
|
32
|
+
default_options = { async: 1 }
|
33
|
+
options.merge!(default_options)
|
34
|
+
options = @options.merge({ body: options.to_query })
|
35
|
+
self.class.post "/draft/classify/#{classifier_id}", options
|
36
|
+
end
|
37
|
+
|
38
|
+
def classify_result(ticket_id)
|
39
|
+
self.class.get "/draft/classify/result/#{ticket_id}", @options
|
40
|
+
end
|
41
|
+
|
42
|
+
def task_result(task_id)
|
43
|
+
self.class.get "/draft/tasks/#{task_id}", @options
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Imagga
|
2
|
+
module Categorization
|
3
|
+
module Configuration
|
4
|
+
VALID_CONNECTION_KEYS = [:endpoint, :user_agent].freeze
|
5
|
+
VALID_OPTIONS_KEYS = [:api_key].freeze
|
6
|
+
VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
|
7
|
+
|
8
|
+
DEFAULT_ENDPOINT = 'http://api.imagga.com/'
|
9
|
+
DEFAULT_USER_AGENT = "Imagga Categorization API ruby Gem #{Categorization::VERSION}".freeze
|
10
|
+
|
11
|
+
DEFAULT_APP_KEY = nil
|
12
|
+
|
13
|
+
attr_accessor *VALID_CONFIG_KEYS
|
14
|
+
|
15
|
+
# Make sure we have the default values set when we get 'extended'
|
16
|
+
def self.extended(base)
|
17
|
+
base.reset
|
18
|
+
end
|
19
|
+
|
20
|
+
def reset
|
21
|
+
self.endpoint = DEFAULT_ENDPOINT
|
22
|
+
self.user_agent = DEFAULT_USER_AGENT
|
23
|
+
|
24
|
+
self.api_key = DEFAULT_APP_KEY
|
25
|
+
end
|
26
|
+
|
27
|
+
def configure
|
28
|
+
yield self
|
29
|
+
end
|
30
|
+
|
31
|
+
def options
|
32
|
+
Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Imagga
|
4
|
+
describe Categorization::Client do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@keys = Categorization::Configuration::VALID_CONFIG_KEYS
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'with module configuration' do
|
11
|
+
before do
|
12
|
+
Categorization.configure do |config|
|
13
|
+
@keys.each do |key|
|
14
|
+
config.send("#{key}=", key)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
after do
|
20
|
+
Categorization.reset
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should inherit module configuration" do
|
24
|
+
api = Categorization::Client.new
|
25
|
+
@keys.each do |key|
|
26
|
+
api.send(key).should == key
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'with class configuration' do
|
31
|
+
before do
|
32
|
+
@config = {
|
33
|
+
:app_key => 'ak',
|
34
|
+
:endpoint => 'ep',
|
35
|
+
:user_agent => 'ua',
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should override module configuration' do
|
40
|
+
api = Categorization::Client.new(@config)
|
41
|
+
@keys.each do |key|
|
42
|
+
api.send(key).should == @config[key]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should override module configuration after' do
|
47
|
+
api = Categorization::Client.new
|
48
|
+
|
49
|
+
@config.each do |key, value|
|
50
|
+
api.send("#{key}=", value)
|
51
|
+
end
|
52
|
+
|
53
|
+
@keys.each do |key|
|
54
|
+
api.send("#{key}").should == @config[key]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'POST classify' do
|
62
|
+
it 'should have a classify method' do
|
63
|
+
client = Categorization::Client.new
|
64
|
+
client.should be_respond_to(:classify)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "must parse the api response from JSON to Hash" do
|
68
|
+
client = Categorization::Client.new
|
69
|
+
client.classify('test').should be_instance_of Hash
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe 'GET classify result' do
|
74
|
+
it 'should have a classify_result method' do
|
75
|
+
client = Categorization::Client.new
|
76
|
+
client.should be_respond_to(:classify_result)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "must parse the api response from JSON to Hash" do
|
80
|
+
client = Categorization::Client.new
|
81
|
+
client.classify_result('ticket_id').should be_instance_of Hash
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe 'GET tasks result' do
|
86
|
+
it 'should have a tasks method' do
|
87
|
+
client = Categorization::Client.new
|
88
|
+
client.should be_respond_to(:tasks)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "must parse the api response from JSON to Hash" do
|
92
|
+
client = Categorization::Client.new
|
93
|
+
client.classify_result('task_id').should be_instance_of Hash
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Imagga
|
4
|
+
describe Categorization do
|
5
|
+
|
6
|
+
describe '.app_key' do
|
7
|
+
it 'should return default key' do
|
8
|
+
Categorization.app_key.should == Categorization::Configuration::DEFAULT_APP_KEY
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.user_agent' do
|
13
|
+
it 'should return default user agent' do
|
14
|
+
Categorization.user_agent.should == Categorization::Configuration::DEFAULT_USER_AGENT
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
after do
|
19
|
+
Categorization.reset
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.configure' do
|
23
|
+
Categorization::Configuration::VALID_CONFIG_KEYS.each do |key|
|
24
|
+
describe ".#{key}" do
|
25
|
+
it 'should return the default value' do
|
26
|
+
Categorization.send(key).should == Categorization::Configuration.const_get("DEFAULT_#{key.upcase}")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "imagga/categorization"
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imagga-categorization
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Benjamin Grelié
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Ruby client for accessing Imagga categorization & training API
|
63
|
+
email:
|
64
|
+
- benjamin@printicapp.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- imagga-categorization.gemspec
|
76
|
+
- imagga-categorization_spec.rb
|
77
|
+
- lib/imagga/categorization.rb
|
78
|
+
- lib/imagga/categorization/client.rb
|
79
|
+
- lib/imagga/categorization/configuration.rb
|
80
|
+
- lib/imagga/categorization/version.rb
|
81
|
+
- spec/lib/client_spec.rb
|
82
|
+
- spec/lib/configuration_spec.rb
|
83
|
+
- spec/lib/imagga-categorization_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
homepage: http://github.com/printic/imagga-categorization
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.8.23
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: Ruby client for accessing Imagga categorization & training API
|
110
|
+
test_files:
|
111
|
+
- spec/lib/client_spec.rb
|
112
|
+
- spec/lib/configuration_spec.rb
|
113
|
+
- spec/lib/imagga-categorization_spec.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
has_rdoc:
|