imagga_auto_tag 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/imagga_auto_tag/tagged_image.rb +6 -2
- data/lib/imagga_auto_tag/version.rb +1 -1
- data/spec/cassettes/image.yml +62 -98
- data/spec/cassettes/no_download.yml +47 -0
- data/spec/imagga_auto_tag_spec.rb +28 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8c6708793a0b4cfc8933fe55e7a14976725b1ce
|
4
|
+
data.tar.gz: 237191d725152c0c03f95093ae9a3ffc08e7d39e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e6eb7125ae2722c7981262e03a1e00da0b3d4ed8815d3815c68afb305b0e6af9ec5de7df02f5165e5b16348111d57c677eaca881dfb5de400a80941e0d047a9
|
7
|
+
data.tar.gz: e2b0e4142582bf83807357a1ce54392cfda484f2f60bea6cc166203417695074802a3bf617472bde07ae61223e1ccdfd691075b19a6ef9e9dff4ab47c1aed5e0
|
@@ -5,15 +5,19 @@ module ImaggaAutoTag
|
|
5
5
|
attr_reader :status, :tags
|
6
6
|
|
7
7
|
def initialize(api_response)
|
8
|
+
|
8
9
|
# The response from Imagga is now wrap in a results envelop
|
9
10
|
#
|
10
11
|
# ==== Result
|
12
|
+
# success:
|
11
13
|
# { "results" => [{ "image" => "", "tags" => [{}, {}, {}] }] }
|
14
|
+
# failure:
|
15
|
+
# { "results" => [], "unsuccessful" => [{ "image" => url, "message" => msg }]}
|
12
16
|
body = JSON.parse(api_response.body)
|
13
17
|
|
14
18
|
@tags = []
|
15
19
|
|
16
|
-
body['results'][0]
|
20
|
+
(body['results'][0] || {}).fetch('tags', []).each do |tag|
|
17
21
|
@tags.push Tag.new(tag)
|
18
22
|
end
|
19
23
|
|
@@ -27,7 +31,7 @@ module ImaggaAutoTag
|
|
27
31
|
end
|
28
32
|
|
29
33
|
def to_csv
|
30
|
-
@tags.collect
|
34
|
+
@tags.collect(&:name).join(',')
|
31
35
|
end
|
32
36
|
|
33
37
|
end
|
data/spec/cassettes/image.yml
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://api.imagga.com/
|
5
|
+
uri: https://api.imagga.com/v1/tagging?url=http://static.ddmcdn.com/gif/landscape-photography-1.jpg
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
9
9
|
headers:
|
10
10
|
User-Agent:
|
11
|
-
- Faraday v0.9.
|
11
|
+
- Faraday v0.9.1
|
12
12
|
Accept-Encoding:
|
13
13
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
14
|
Accept:
|
@@ -18,108 +18,72 @@ http_interactions:
|
|
18
18
|
code: 200
|
19
19
|
message: OK
|
20
20
|
headers:
|
21
|
-
|
22
|
-
-
|
23
|
-
|
24
|
-
-
|
21
|
+
Access-Control-Allow-Headers:
|
22
|
+
- content-type, accept, cache-control, x-requested-with, authorization
|
23
|
+
Access-Control-Allow-Methods:
|
24
|
+
- GET
|
25
|
+
Access-Control-Allow-Origin:
|
26
|
+
- "*"
|
27
|
+
Access-Control-Max-Age:
|
28
|
+
- '60'
|
25
29
|
Content-Type:
|
26
30
|
- application/json
|
31
|
+
Date:
|
32
|
+
- Wed, 06 May 2015 19:44:17 GMT
|
33
|
+
Server:
|
34
|
+
- nginx/1.4.6 (Ubuntu)
|
35
|
+
Set-Cookie:
|
36
|
+
- session=eyJyZXF1ZXN0X2lkIjp7IiBiIjoiTXpRM09EcGhZMk5mT0Raa016WmxZamM0WXpBMFl6TXcifX0.CCwAkQ.8QdcpHTw7p_0cKyNo2s5Sp-PE50;
|
37
|
+
HttpOnly; Path=/
|
27
38
|
Content-Length:
|
28
|
-
- '
|
39
|
+
- '3394'
|
29
40
|
Connection:
|
30
41
|
- keep-alive
|
31
|
-
Access-Control-Allow-Origin:
|
32
|
-
- "*"
|
33
|
-
Access-Control-Allow-Methods:
|
34
|
-
- OPTIONS, PUT, GET, POST, DELETE
|
35
|
-
Access-Control-Allow-Headers:
|
36
|
-
- content-type, accept, cache-control, x-requested-with
|
37
|
-
Access-Control-Max-Age:
|
38
|
-
- '60'
|
39
42
|
body:
|
40
43
|
encoding: UTF-8
|
41
|
-
string:
|
42
|
-
|
43
|
-
45.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
\ \"confidence\": 15.829675488345195, \n \"tag\": \"tree\"\n
|
85
|
-
\ }, \n {\n \"confidence\": 15.24591685171035, \n
|
86
|
-
\ \"tag\": \"plain\"\n }, \n {\n \"confidence\":
|
87
|
-
15.071062582287361, \n \"tag\": \"scene\"\n }, \n {\n
|
88
|
-
\ \"confidence\": 14.274802746575993, \n \"tag\": \"day\"\n
|
89
|
-
\ }, \n {\n \"confidence\": 13.820782181417332, \n
|
90
|
-
\ \"tag\": \"hill\"\n }, \n {\n \"confidence\":
|
91
|
-
13.37486025558128, \n \"tag\": \"natural\"\n }, \n {\n
|
92
|
-
\ \"confidence\": 13.367081765784242, \n \"tag\": \"farming\"\n
|
93
|
-
\ }, \n {\n \"confidence\": 12.898074060896516, \n
|
94
|
-
\ \"tag\": \"scenic\"\n }, \n {\n \"confidence\":
|
95
|
-
10.999456006061584, \n \"tag\": \"fields\"\n }, \n {\n
|
96
|
-
\ \"confidence\": 10.287484889012664, \n \"tag\": \"grassland\"\n
|
97
|
-
\ }, \n {\n \"confidence\": 10.19599186203595, \n
|
98
|
-
\ \"tag\": \"farmland\"\n }, \n {\n \"confidence\":
|
99
|
-
10.151697168209193, \n \"tag\": \"fresh\"\n }, \n {\n
|
100
|
-
\ \"confidence\": 10.061411487391338, \n \"tag\": \"park\"\n
|
101
|
-
\ }, \n {\n \"confidence\": 10.055026818532369, \n
|
102
|
-
\ \"tag\": \"flora\"\n }, \n {\n \"confidence\":
|
103
|
-
9.471499129485952, \n \"tag\": \"sunset\"\n }, \n {\n
|
104
|
-
\ \"confidence\": 9.435488194403247, \n \"tag\": \"tranquil\"\n
|
105
|
-
\ }, \n {\n \"confidence\": 8.944498856145206, \n
|
106
|
-
\ \"tag\": \"travel\"\n }, \n {\n \"confidence\":
|
107
|
-
8.836695582313878, \n \"tag\": \"freedom\"\n }, \n {\n
|
108
|
-
\ \"confidence\": 8.68426390350368, \n \"tag\": \"colorful\"\n
|
109
|
-
\ }, \n {\n \"confidence\": 8.358216968823195, \n
|
110
|
-
\ \"tag\": \"vibrant\"\n }, \n {\n \"confidence\":
|
111
|
-
8.260337283211635, \n \"tag\": \"idyllic\"\n }, \n {\n
|
112
|
-
\ \"confidence\": 8.182653073843216, \n \"tag\": \"sunrise\"\n
|
113
|
-
\ }, \n {\n \"confidence\": 8.01481616674438, \n \"tag\":
|
114
|
-
\"peaceful\"\n }, \n {\n \"confidence\": 8.011175205099152,
|
115
|
-
\n \"tag\": \"bright\"\n }, \n {\n \"confidence\":
|
116
|
-
7.933190186126691, \n \"tag\": \"color\"\n }, \n {\n
|
117
|
-
\ \"confidence\": 7.860003741597381, \n \"tag\": \"yellow\"\n
|
118
|
-
\ }, \n {\n \"confidence\": 7.8105899950891775, \n
|
119
|
-
\ \"tag\": \"lea\"\n }, \n {\n \"confidence\":
|
120
|
-
7.76446030144356, \n \"tag\": \"heavens\"\n }, \n {\n
|
121
|
-
\ \"confidence\": 7.650482427445872, \n \"tag\": \"vista\"\n
|
122
|
-
\ }\n ]\n}\n"
|
44
|
+
string: '{"results": [{"image": "http://static.ddmcdn.com/gif/landscape-photography-1.jpg",
|
45
|
+
"tags": [{"confidence": 47.16994169669641, "tag": "grassland"}, {"confidence":
|
46
|
+
45.87292709198188, "tag": "field"}, {"confidence": 45.019462539740665, "tag":
|
47
|
+
"grass"}, {"confidence": 41.53961668314429, "tag": "meadow"}, {"confidence":
|
48
|
+
37.681753983890346, "tag": "landscape"}, {"confidence": 34.47865251401469,
|
49
|
+
"tag": "summer"}, {"confidence": 33.13395846563346, "tag": "sky"}, {"confidence":
|
50
|
+
29.98744017425953, "tag": "rural"}, {"confidence": 28.823619529162976, "tag":
|
51
|
+
"countryside"}, {"confidence": 27.13108249060661, "tag": "country"}, {"confidence":
|
52
|
+
27.093789115260403, "tag": "spring"}, {"confidence": 25.714842590319137, "tag":
|
53
|
+
"farm"}, {"confidence": 24.336827462837437, "tag": "horizon"}, {"confidence":
|
54
|
+
24.115280098473487, "tag": "clouds"}, {"confidence": 23.56170759210806, "tag":
|
55
|
+
"sun"}, {"confidence": 23.55661808909411, "tag": "agriculture"}, {"confidence":
|
56
|
+
22.64203743558242, "tag": "cloud"}, {"confidence": 22.567807470484027, "tag":
|
57
|
+
"sunny"}, {"confidence": 21.692051154694852, "tag": "plant"}, {"confidence":
|
58
|
+
21.4697106723974, "tag": "environment"}, {"confidence": 20.80800692342329,
|
59
|
+
"tag": "outdoor"}, {"confidence": 20.27380472909292, "tag": "pasture"}, {"confidence":
|
60
|
+
19.97223882234847, "tag": "weather"}, {"confidence": 19.672755524643385, "tag":
|
61
|
+
"season"}, {"confidence": 19.129671260375478, "tag": "lawn"}, {"confidence":
|
62
|
+
18.091295375332248, "tag": "outdoors"}, {"confidence": 17.820118550230625,
|
63
|
+
"tag": "land"}, {"confidence": 17.533736629067555, "tag": "cloudscape"}, {"confidence":
|
64
|
+
17.227521322226266, "tag": "scenery"}, {"confidence": 17.052192266625703,
|
65
|
+
"tag": "sunlight"}, {"confidence": 16.598898715047728, "tag": "outside"},
|
66
|
+
{"confidence": 16.490149489526726, "tag": "cloudy"}, {"confidence": 15.857062392231025,
|
67
|
+
"tag": "clear"}, {"confidence": 15.829675413246951, "tag": "tree"}, {"confidence":
|
68
|
+
15.245916761118902, "tag": "plain"}, {"confidence": 15.071062575498514, "tag":
|
69
|
+
"scene"}, {"confidence": 14.27480271119219, "tag": "day"}, {"confidence":
|
70
|
+
13.82078217457135, "tag": "hill"}, {"confidence": 13.374860237309415, "tag":
|
71
|
+
"natural"}, {"confidence": 13.36708172941655, "tag": "farming"}, {"confidence":
|
72
|
+
12.898074033486186, "tag": "scenic"}, {"confidence": 10.999455994858698, "tag":
|
73
|
+
"fields"}, {"confidence": 10.195991836252425, "tag": "farmland"}, {"confidence":
|
74
|
+
10.151697163068523, "tag": "fresh"}, {"confidence": 10.061411482100615, "tag":
|
75
|
+
"park"}, {"confidence": 10.055026806986385, "tag": "flora"}, {"confidence":
|
76
|
+
9.471499078203692, "tag": "sunset"}, {"confidence": 9.435488154330805, "tag":
|
77
|
+
"tranquil"}, {"confidence": 8.944498847707003, "tag": "travel"}, {"confidence":
|
78
|
+
8.836695580961415, "tag": "freedom"}, {"confidence": 8.68426388253624, "tag":
|
79
|
+
"colorful"}, {"confidence": 8.6, "tag": "eatage"}, {"confidence": 8.358216918457762,
|
80
|
+
"tag": "vibrant"}, {"confidence": 8.260337223076979, "tag": "idyllic"}, {"confidence":
|
81
|
+
8.182653016504954, "tag": "sunrise"}, {"confidence": 8.014816123314208, "tag":
|
82
|
+
"peaceful"}, {"confidence": 8.011175189956885, "tag": "bright"}, {"confidence":
|
83
|
+
7.933190150800882, "tag": "color"}, {"confidence": 7.860003745787088, "tag":
|
84
|
+
"yellow"}, {"confidence": 7.810589998365093, "tag": "lea"}, {"confidence":
|
85
|
+
7.793729720904508, "tag": "oak"}, {"confidence": 7.764460287180423, "tag":
|
86
|
+
"heavens"}, {"confidence": 7.650482355660379, "tag": "vista"}]}]}'
|
123
87
|
http_version:
|
124
|
-
recorded_at: Wed,
|
88
|
+
recorded_at: Wed, 06 May 2015 19:43:07 GMT
|
125
89
|
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,47 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.imagga.com/v1/tagging?url=http://static.ddmcdn.com/gif/landscape-photography-1.jpg
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.9.1
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Access-Control-Allow-Headers:
|
22
|
+
- content-type, accept, cache-control, x-requested-with, authorization
|
23
|
+
Access-Control-Allow-Methods:
|
24
|
+
- GET
|
25
|
+
Access-Control-Allow-Origin:
|
26
|
+
- "*"
|
27
|
+
Access-Control-Max-Age:
|
28
|
+
- '60'
|
29
|
+
Content-Type:
|
30
|
+
- application/json
|
31
|
+
Date:
|
32
|
+
- Wed, 06 May 2015 19:44:17 GMT
|
33
|
+
Server:
|
34
|
+
- nginx/1.4.6 (Ubuntu)
|
35
|
+
Set-Cookie:
|
36
|
+
- session=eyJyZXF1ZXN0X2lkIjp7IiBiIjoiTXpRM09EcGhZMk5mT0Raa016WmxZamM0WXpBMFl6TXcifX0.CCwAkQ.8QdcpHTw7p_0cKyNo2s5Sp-PE50;
|
37
|
+
HttpOnly; Path=/
|
38
|
+
Content-Length:
|
39
|
+
- '184'
|
40
|
+
Connection:
|
41
|
+
- keep-alive
|
42
|
+
body:
|
43
|
+
encoding: UTF-8
|
44
|
+
string: '{"results":[],"unsuccessful":[{"image":"https://unsplash.imgix.net/test-photo-21?q=75&fm=jpg&w=1080&fit=max&s=5d249291d47454d1c7bfac41318df561","message":"Could not download image."}]}'
|
45
|
+
http_version:
|
46
|
+
recorded_at: Wed, 06 May 2015 19:43:07 GMT
|
47
|
+
recorded_with: VCR 2.9.3
|
@@ -18,7 +18,7 @@ describe "An Imagga Auto Tag API" do
|
|
18
18
|
|
19
19
|
end
|
20
20
|
|
21
|
-
context "result" do
|
21
|
+
context "successful result" do
|
22
22
|
|
23
23
|
before do
|
24
24
|
VCR.use_cassette('image') do
|
@@ -58,4 +58,31 @@ describe "An Imagga Auto Tag API" do
|
|
58
58
|
|
59
59
|
end
|
60
60
|
|
61
|
+
context "could not download image" do
|
62
|
+
|
63
|
+
before do
|
64
|
+
VCR.use_cassette('no_download') do
|
65
|
+
@client = ImaggaAutoTag::Client.new(ENV['IMAGGA_API_KEY'], ENV['IMAGGA_API_SECRET'])
|
66
|
+
@results = @client.fetch("http://static.ddmcdn.com/gif/landscape-photography-1.jpg")
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns a tagged image object" do
|
71
|
+
expect(@results).to be_an_instance_of(ImaggaAutoTag::TaggedImage)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "has a status code" do
|
75
|
+
expect(@results.status).to be 200
|
76
|
+
end
|
77
|
+
|
78
|
+
it "does not have tags" do
|
79
|
+
expect(@results.tags).to be_empty
|
80
|
+
end
|
81
|
+
|
82
|
+
it "csv is empty string" do
|
83
|
+
expect(@results.to_csv).to eq ""
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
61
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imagga_auto_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Chesser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/imagga_auto_tag/tagged_image.rb
|
129
129
|
- lib/imagga_auto_tag/version.rb
|
130
130
|
- spec/cassettes/image.yml
|
131
|
+
- spec/cassettes/no_download.yml
|
131
132
|
- spec/imagga_auto_tag_spec.rb
|
132
133
|
- spec/spec_helper.rb
|
133
134
|
homepage: ''
|
@@ -156,5 +157,6 @@ specification_version: 4
|
|
156
157
|
summary: Simple wrapper around the Imagga Auto Tagging API
|
157
158
|
test_files:
|
158
159
|
- spec/cassettes/image.yml
|
160
|
+
- spec/cassettes/no_download.yml
|
159
161
|
- spec/imagga_auto_tag_spec.rb
|
160
162
|
- spec/spec_helper.rb
|