docomo_image_recognition 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +35 -0
- data/Rakefile +17 -0
- data/lib/docomo_image_recognition/client.rb +55 -0
- data/lib/docomo_image_recognition/configuration.rb +9 -0
- data/lib/docomo_image_recognition/error.rb +14 -0
- data/lib/docomo_image_recognition/version.rb +6 -0
- data/lib/docomo_image_recognition.rb +17 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ef826684f40faddb76c2a6bce951e932e471fd9b
|
4
|
+
data.tar.gz: 118d6694e146b0dff2717d4b7128c3c278fe399e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b76d2a6f82173bcdd303e50a1e5453241d2c13b3f967825d1436defdd32cd2df429f2cc5fac821bf7a1ec2d50f74c3ef13f9ab45e89de3161b5a26c61247a557
|
7
|
+
data.tar.gz: 8d07e368d0af6127c6cf1c0f3de72d2d8db2f5d8f556f1a78fc568a8b52944c12eee385fd0f27e28024202ba08d1113c04593f02cf4f5fe231384c81886c9317
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 Claude Tech
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Docomo Image Recognition
|
2
|
+
|
3
|
+
Ruby SDK for Docomo recognition API.
|
4
|
+
https://dev.smt.docomo.ne.jp/?p=docs.api.page&api_docs_id=105
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add
|
9
|
+
|
10
|
+
```
|
11
|
+
gem 'docomo_image_recognition'
|
12
|
+
```
|
13
|
+
|
14
|
+
to your Gemfile or install it manually with
|
15
|
+
|
16
|
+
```sh
|
17
|
+
$ gem install docomo_image_recognition
|
18
|
+
```
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
To use this API, you first need to get an API key from [Docomo developer page](https://dev.smt.docomo.ne.jp/?p=login).
|
23
|
+
|
24
|
+
Then, you can use it the following way:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
API_KEY = 'api you just got'
|
28
|
+
client = DocomoImageRecognition::Client.new(API_KEY)
|
29
|
+
client.recognize_from_url('http://the_url_you_want_to_anlayze.com/image.jpg')
|
30
|
+
client.recognize_from_file('/path/to/file/to/analyze.jpg')
|
31
|
+
```
|
32
|
+
|
33
|
+
Both method return the response in JSON format.
|
34
|
+
|
35
|
+
If an error occurs, a `DocomoImageRecognition::ApiError` is thrown.
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'CdnTags'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module DocomoImageRecognition
|
2
|
+
class Client
|
3
|
+
def initialize(api_key)
|
4
|
+
base_url = DocomoImageRecognition.configuration.base_url
|
5
|
+
@base_url = base_url + "?APIKEY=#{api_key}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def recognize(data, options = default_options)
|
9
|
+
url = "#{@base_url}&#{to_query(options)}"
|
10
|
+
curl = Curl::Easy.new(url)
|
11
|
+
curl.headers['Content-Type'] = 'application/octet-stream'
|
12
|
+
curl.post_body = data
|
13
|
+
curl.http_post
|
14
|
+
body = JSON.parse(curl.body_str)
|
15
|
+
raise_on_error!(body, curl.status)
|
16
|
+
body
|
17
|
+
end
|
18
|
+
|
19
|
+
def recognize_from_file(path, options = default_options)
|
20
|
+
data = File.read(path)
|
21
|
+
recognize(data, options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def recognize_from_url(url, options = default_options)
|
25
|
+
data = download_file(url)
|
26
|
+
recognize(data, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def download_file(url)
|
32
|
+
uri = URI(url)
|
33
|
+
Net::HTTP.get(uri)
|
34
|
+
end
|
35
|
+
|
36
|
+
def default_options
|
37
|
+
{ recog: 'product-all', numOfCandidates: 10 }
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_query(options)
|
41
|
+
options
|
42
|
+
.reject { |_k, v| v.nil? }
|
43
|
+
.map { |k, v| k.to_s + '=' + v.to_s }
|
44
|
+
.join('&')
|
45
|
+
end
|
46
|
+
|
47
|
+
def raise_on_error!(body, status)
|
48
|
+
case status.split(' ')[0].to_i
|
49
|
+
when 200 then return
|
50
|
+
when 401 then fail 'not authorized', ApiError.new(body)
|
51
|
+
when 400 then fail 'bad request', ApiError.new(body)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'curb'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
%w(error configuration client).each do |m|
|
6
|
+
require File.join(File.dirname(__FILE__), 'docomo_image_recognition', m)
|
7
|
+
end
|
8
|
+
|
9
|
+
module DocomoImageRecognition
|
10
|
+
def self.configuration
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.configure
|
15
|
+
yield configuration
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: docomo_image_recognition
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Perez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: curb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- daniel@claudetech.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README.md
|
50
|
+
- Rakefile
|
51
|
+
- lib/docomo_image_recognition.rb
|
52
|
+
- lib/docomo_image_recognition/client.rb
|
53
|
+
- lib/docomo_image_recognition/configuration.rb
|
54
|
+
- lib/docomo_image_recognition/error.rb
|
55
|
+
- lib/docomo_image_recognition/version.rb
|
56
|
+
homepage: https://github.com/HackathonMonster/docomo-image-recognition
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.2
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: SDK for Docomo image recognition API
|
80
|
+
test_files: []
|