ditto_api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ditto/client.rb +39 -0
- data/lib/ditto/error.rb +7 -0
- data/lib/ditto/face.rb +13 -0
- data/lib/ditto/image.rb +51 -0
- data/lib/ditto/logo.rb +17 -0
- data/lib/ditto/mood.rb +13 -0
- data/lib/ditto.rb +9 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d53ba478122a7215914b4b6e5ca21b53917f67e2
|
4
|
+
data.tar.gz: 970e89b2f0a3e90247462e0303bff097b56603d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b74a4f829bdd0a7239a56f278d5a9ee9e36bfcf1a11873751a0e1d1b0356472518fe39a5e4c0846c2247a9da77f15446b09e63ef1f7587b3f29118409c799eb
|
7
|
+
data.tar.gz: 99afd7e520212d277fedcaf20885d7da5e7b5a88817d4bf1171fd711dfc9ee00fb83b0ae98ddeaab0be8bbbf152a23b502052296027699b64512f59dcabc150e
|
data/lib/ditto/client.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module Ditto
|
2
|
+
class Client
|
3
|
+
attr_reader :client_id
|
4
|
+
|
5
|
+
def initialize(client_id)
|
6
|
+
@client_id = client_id
|
7
|
+
end
|
8
|
+
|
9
|
+
def find(url, id)
|
10
|
+
response = Net::HTTP.get_response(find_uri(url, id))
|
11
|
+
|
12
|
+
case response.code
|
13
|
+
when "200"
|
14
|
+
Image.new(JSON.parse(response.body, symbolize_names: true))
|
15
|
+
when "408"
|
16
|
+
raise ImageTimeoutError
|
17
|
+
when "415"
|
18
|
+
raise InvalidImageError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_uri(url, id)
|
23
|
+
URI::HTTP.build(
|
24
|
+
host: "ondemand-p02-api.ditto.us.com",
|
25
|
+
path: "/v1/find",
|
26
|
+
query: encoded(image_match_params(url, id)))
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def encoded(params)
|
32
|
+
URI.encode_www_form(params).gsub("+", "%20")
|
33
|
+
end
|
34
|
+
|
35
|
+
def image_match_params(url, id)
|
36
|
+
{ client_id: client_id, url: url, uid: id }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/ditto/error.rb
ADDED
data/lib/ditto/face.rb
ADDED
data/lib/ditto/image.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Ditto
|
2
|
+
class Image
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize(response)
|
6
|
+
@response = response
|
7
|
+
end
|
8
|
+
|
9
|
+
def url
|
10
|
+
response[:url]
|
11
|
+
end
|
12
|
+
|
13
|
+
def image_id
|
14
|
+
response[:uid]
|
15
|
+
end
|
16
|
+
|
17
|
+
def width
|
18
|
+
data[:image_width]
|
19
|
+
end
|
20
|
+
|
21
|
+
def height
|
22
|
+
data[:image_height]
|
23
|
+
end
|
24
|
+
|
25
|
+
def faces
|
26
|
+
faces_array.map { |face| Face.new(face) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def moods
|
30
|
+
moods_array.map { |mood| Mood.new(mood) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def logos
|
34
|
+
data[:matches].map { |logo| Logo.new(logo) }
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def data
|
40
|
+
response[:data]
|
41
|
+
end
|
42
|
+
|
43
|
+
def faces_array
|
44
|
+
data[:faces] || []
|
45
|
+
end
|
46
|
+
|
47
|
+
def moods_array
|
48
|
+
data[:moods] || []
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/ditto/logo.rb
ADDED
data/lib/ditto/mood.rb
ADDED
data/lib/ditto.rb
ADDED
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ditto_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Sheehan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
description:
|
42
|
+
email: adam@ditto.us.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/ditto.rb
|
48
|
+
- lib/ditto/client.rb
|
49
|
+
- lib/ditto/error.rb
|
50
|
+
- lib/ditto/face.rb
|
51
|
+
- lib/ditto/image.rb
|
52
|
+
- lib/ditto/logo.rb
|
53
|
+
- lib/ditto/mood.rb
|
54
|
+
homepage:
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.4.5
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: A Ruby interface to the Ditto Photo Reader API.
|
78
|
+
test_files: []
|