imagga_auto_tag 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +14 -0
- data/README.md +3 -1
- data/Rakefile +24 -1
- data/imagga_auto_tag.gemspec +14 -14
- data/lib/imagga_auto_tag.rb +7 -6
- data/lib/imagga_auto_tag/client.rb +4 -8
- data/lib/imagga_auto_tag/imagga_error.rb +11 -0
- data/lib/imagga_auto_tag/tag.rb +1 -5
- data/lib/imagga_auto_tag/tagged_image.rb +13 -10
- data/lib/imagga_auto_tag/version.rb +1 -1
- data/spec/cassettes/image.yml +71 -51
- data/spec/cassettes/no_download.yml +19 -10
- data/spec/imagga_auto_tag_spec.rb +66 -29
- data/spec/spec_helper.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb074258516adf42ee4a2434db608e2bec9336e
|
4
|
+
data.tar.gz: cddc582944f2b5b320161645c191b2019b50dbd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 951340b44400168408357e7f32407f4f96c61648c8d6d68b0cb5f7bfddc75d36938a1094a2240668a988e41d4fd65865460d3fd887ca264db95c241b4447a5f8
|
7
|
+
data.tar.gz: 41586d21ed38f6ad95cbb10ec9cb70db22b5e044d321eb62577f8ba9d65c1315cea130c48160fb1a92043897378af9e9e0808940e7f862465a92f51fd14c1dc4
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
rvm:
|
2
|
+
- 2.3.0
|
3
|
+
language: ruby
|
4
|
+
deploy:
|
5
|
+
provider: rubygems
|
6
|
+
api_key:
|
7
|
+
secure: P6IxTlvw3/UHpByeDkkun+APYvCzPgLhJWuPx+tg4LBRHD3dMAqLdeXufZmhOgSkL6NvTocTOZik04Ilw9/vI1IYKRT6alRpPDHdsx0MnrI9Rs6OXdkIpLga/s7MeuRSI3nIzR0ioDYjjiverdDweujtRetG7rxwCygu52A7OGI=
|
8
|
+
gem: imagga_auto_tag
|
9
|
+
on:
|
10
|
+
tags: true
|
11
|
+
repo: unsplash/imagga-auto-tag
|
12
|
+
env:
|
13
|
+
global:
|
14
|
+
secure: IuQTRlcwjHgRty3TNQHdDNE9NSQA4OrNjS34eD9i1aTstRzhRyYyVOJvCGSo5T8dWClLnx4TTAC73xY+QGXaHNqce9ZzKBI8QCzGAp/h9Z++/Quv67Vtn0a+HhYSScWpGAp+Rz3sGFq9Q8Yu58KTDLnZF0SUvIURzCpBF+36R6k=
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# ImaggaAutoTag
|
2
2
|
|
3
|
+
[![](https://travis-ci.org/unsplash/imagga-auto-tag.svg?&branch=master)](https://travis-ci.org/unsplash/imagga-auto-tag)
|
4
|
+
|
3
5
|
Ruby client for fetching tags for an image using the [Imagga Auto Tagging API](http://imagga.com/solutions/auto-tagging.html).
|
4
6
|
|
5
7
|
## Installation
|
@@ -42,7 +44,7 @@ results.to_csv
|
|
42
44
|
|
43
45
|
## Contributing
|
44
46
|
|
45
|
-
1. Fork it ( https://github.com/
|
47
|
+
1. Fork it ( https://github.com/crewlabs/imagga_auto_tag/fork )
|
46
48
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
49
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
50
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -1,2 +1,25 @@
|
|
1
|
-
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), "lib")
|
2
2
|
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'imagga_auto_tag/version'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
task :default => :spec
|
9
|
+
task :release do
|
10
|
+
puts "=> TravisCI handles the release. So this task will create a tag and push it"
|
11
|
+
`git pull --tags`
|
12
|
+
|
13
|
+
version = ImaggaAutoTag::VERSION
|
14
|
+
`git tag | grep #{version}`
|
15
|
+
already_exists = $?.exitstatus == 0
|
16
|
+
if already_exists
|
17
|
+
puts "-> v#{version} already exists, consider bumping"
|
18
|
+
exit(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
`git tag v#{version}`
|
22
|
+
puts "=> Pushing tags"
|
23
|
+
`git push --tags`
|
24
|
+
puts "=> Version #{version} pushed!"
|
25
|
+
end
|
data/imagga_auto_tag.gemspec
CHANGED
@@ -4,26 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'imagga_auto_tag/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'imagga_auto_tag'
|
8
8
|
spec.version = ImaggaAutoTag::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
11
|
-
spec.summary =
|
12
|
-
spec.homepage =
|
13
|
-
spec.license =
|
9
|
+
spec.authors = ['Luke Chesser', 'Unsplash Team']
|
10
|
+
spec.email = ['dev@unsplash.com']
|
11
|
+
spec.summary = 'Simple wrapper around the Imagga Auto Tagging API'
|
12
|
+
spec.homepage = 'https://github.com/crewlabs/imagga_auto_tag/'
|
13
|
+
spec.license = 'MIT'
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
16
16
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
-
spec.require_paths = [
|
18
|
+
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.add_development_dependency
|
21
|
-
spec.add_development_dependency
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'vcr'
|
25
|
+
spec.add_development_dependency 'webmock'
|
26
26
|
|
27
|
-
spec.add_dependency
|
28
|
-
spec.add_dependency
|
27
|
+
spec.add_dependency 'faraday'
|
28
|
+
spec.add_dependency 'json'
|
29
29
|
end
|
data/lib/imagga_auto_tag.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'imagga_auto_tag/version'
|
4
|
+
require 'imagga_auto_tag/client'
|
5
|
+
require 'imagga_auto_tag/tagged_image'
|
6
|
+
require 'imagga_auto_tag/tag'
|
7
|
+
require 'imagga_auto_tag/imagga_error'
|
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'base64'
|
2
2
|
|
3
3
|
module ImaggaAutoTag
|
4
|
-
|
5
4
|
class Client
|
6
|
-
|
7
|
-
|
8
|
-
IMAGGA_API_TAG_PATH = "/v1/tagging"
|
5
|
+
IMAGGA_API_BASE_URL = 'https://api.imagga.com'.freeze
|
6
|
+
IMAGGA_API_TAG_PATH = '/v1/tagging'.freeze
|
9
7
|
|
10
8
|
attr_reader :response
|
11
9
|
|
@@ -32,11 +30,9 @@ module ImaggaAutoTag
|
|
32
30
|
# client = ImaggaAutoTag::Client.new(api_key, api_secret)
|
33
31
|
# client.fetch(image_url_string)
|
34
32
|
def fetch(url)
|
35
|
-
@response = @conn.get IMAGGA_API_TAG_PATH,
|
33
|
+
@response = @conn.get IMAGGA_API_TAG_PATH, url: url
|
36
34
|
|
37
35
|
TaggedImage.new(@response)
|
38
36
|
end
|
39
|
-
|
40
37
|
end
|
41
|
-
|
42
|
-
end
|
38
|
+
end
|
data/lib/imagga_auto_tag/tag.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
1
|
module ImaggaAutoTag
|
2
|
-
|
3
2
|
class TaggedImage
|
4
|
-
|
5
3
|
attr_reader :status, :tags
|
6
4
|
|
7
5
|
def initialize(api_response)
|
8
|
-
|
9
6
|
# The response from Imagga is now wrap in a results envelop
|
10
7
|
#
|
11
8
|
# ==== Result
|
@@ -15,13 +12,21 @@ module ImaggaAutoTag
|
|
15
12
|
# { "results" => [], "unsuccessful" => [{ "image" => url, "message" => msg }]}
|
16
13
|
body = JSON.parse(api_response.body)
|
17
14
|
|
18
|
-
|
19
|
-
|
20
|
-
(body['results'][0] || {}).fetch('tags', []).each do |tag|
|
21
|
-
@tags.push Tag.new(tag)
|
15
|
+
unless api_response.status.between?(200, 299)
|
16
|
+
raise ImaggaError.new(body['type']), body['message']
|
22
17
|
end
|
23
18
|
|
19
|
+
@tags = []
|
24
20
|
@status = api_response.status
|
21
|
+
results = body['results']
|
22
|
+
|
23
|
+
return unless results.any?
|
24
|
+
|
25
|
+
result = results.first || {}
|
26
|
+
|
27
|
+
result.fetch('tags', []).each do |tag|
|
28
|
+
@tags << Tag.new(tag)
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
def scrub(threshold = 30)
|
@@ -33,7 +38,5 @@ module ImaggaAutoTag
|
|
33
38
|
def to_csv
|
34
39
|
@tags.collect(&:name).join(',')
|
35
40
|
end
|
36
|
-
|
37
41
|
end
|
38
|
-
|
39
|
-
end
|
42
|
+
end
|
data/spec/cassettes/image.yml
CHANGED
@@ -8,7 +8,9 @@ http_interactions:
|
|
8
8
|
string: ''
|
9
9
|
headers:
|
10
10
|
User-Agent:
|
11
|
-
- Faraday v0.
|
11
|
+
- Faraday v0.10.0
|
12
|
+
Authorization:
|
13
|
+
- Basic YWNjX2QzNTU2ZmJmMGY4NjdiNTpiNTFmOTgxYzM4ZTVlZTE0ZTVhYjM0ZmEzNjQwNGY3Mg==
|
12
14
|
Accept-Encoding:
|
13
15
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
16
|
Accept:
|
@@ -29,61 +31,79 @@ http_interactions:
|
|
29
31
|
Content-Type:
|
30
32
|
- application/json
|
31
33
|
Date:
|
32
|
-
-
|
34
|
+
- Thu, 15 Dec 2016 19:36:37 GMT
|
35
|
+
Monthly-Limit:
|
36
|
+
- '2000'
|
37
|
+
Monthly-Limit-Remaining:
|
38
|
+
- '1995'
|
39
|
+
Monthly-Limit-Reset:
|
40
|
+
- '1484507658'
|
33
41
|
Server:
|
34
|
-
- nginx/1.
|
42
|
+
- nginx/1.9.15
|
35
43
|
Set-Cookie:
|
36
|
-
- session=
|
37
|
-
|
44
|
+
- session=eyJyZXF1ZXN0X2lkIjpudWxsfQ.CzSCRQ.r1ozqTn3jf1Tvh004O5nlUPPIy4; HttpOnly;
|
45
|
+
Path=/
|
38
46
|
Content-Length:
|
39
|
-
- '
|
47
|
+
- '4329'
|
40
48
|
Connection:
|
41
49
|
- keep-alive
|
42
50
|
body:
|
43
51
|
encoding: UTF-8
|
44
|
-
string: '{"results": [{"image": "http://static.ddmcdn.com/gif/landscape-photography-1.jpg",
|
45
|
-
"tags": [{"confidence":
|
46
|
-
|
47
|
-
"
|
48
|
-
|
49
|
-
"
|
50
|
-
|
51
|
-
"
|
52
|
-
|
53
|
-
"
|
54
|
-
|
55
|
-
"
|
56
|
-
|
57
|
-
"
|
58
|
-
|
59
|
-
"
|
60
|
-
|
61
|
-
"
|
62
|
-
|
63
|
-
"tag": "
|
64
|
-
|
65
|
-
"
|
66
|
-
|
67
|
-
"
|
68
|
-
|
69
|
-
"
|
70
|
-
|
71
|
-
"
|
72
|
-
|
73
|
-
"
|
74
|
-
|
75
|
-
"
|
76
|
-
|
77
|
-
"
|
78
|
-
|
79
|
-
"
|
80
|
-
"tag": "
|
81
|
-
|
82
|
-
"
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
"
|
52
|
+
string: '{"results": [{"tagging_id": null, "image": "http://static.ddmcdn.com/gif/landscape-photography-1.jpg",
|
53
|
+
"tags": [{"confidence": 61.64253543201611, "tag": "field"}, {"confidence":
|
54
|
+
61.21937664290404, "tag": "grass"}, {"confidence": 57.493161203958365, "tag":
|
55
|
+
"grassland"}, {"confidence": 57.200538933090705, "tag": "landscape"}, {"confidence":
|
56
|
+
55.14596006354544, "tag": "farming"}, {"confidence": 53.12386042436984, "tag":
|
57
|
+
"meadow"}, {"confidence": 52.77582358749907, "tag": "rural"}, {"confidence":
|
58
|
+
49.60660844320513, "tag": "sky"}, {"confidence": 49.21200617607885, "tag":
|
59
|
+
"country"}, {"confidence": 48.68550662877986, "tag": "farm"}, {"confidence":
|
60
|
+
48.4115203741488, "tag": "countryside"}, {"confidence": 47.25881969434561,
|
61
|
+
"tag": "cloud"}, {"confidence": 46.69257863340604, "tag": "horizon"}, {"confidence":
|
62
|
+
45.78990314242645, "tag": "summer"}, {"confidence": 43.11377903327924, "tag":
|
63
|
+
"agriculture"}, {"confidence": 42.57386458302678, "tag": "cloudy"}, {"confidence":
|
64
|
+
42.13262591236759, "tag": "clouds"}, {"confidence": 41.02069365484638, "tag":
|
65
|
+
"lawn"}, {"confidence": 40.96118148313501, "tag": "spring"}, {"confidence":
|
66
|
+
39.500539917179076, "tag": "weather"}, {"confidence": 37.45674682172643, "tag":
|
67
|
+
"land"}, {"confidence": 35.992461112398665, "tag": "outdoor"}, {"confidence":
|
68
|
+
35.856355143203544, "tag": "plain"}, {"confidence": 35.70533611893465, "tag":
|
69
|
+
"pasture"}, {"confidence": 34.482182835646334, "tag": "outside"}, {"confidence":
|
70
|
+
33.85066462670361, "tag": "cloudscape"}, {"confidence": 32.240143089284636,
|
71
|
+
"tag": "plant"}, {"confidence": 32.107951444923, "tag": "season"}, {"confidence":
|
72
|
+
31.680475768880402, "tag": "sun"}, {"confidence": 31.61844105733201, "tag":
|
73
|
+
"scenic"}, {"confidence": 30.76507321579469, "tag": "sunlight"}, {"confidence":
|
74
|
+
29.62590301586089, "tag": "scene"}, {"confidence": 28.29813228949009, "tag":
|
75
|
+
"scenery"}, {"confidence": 26.542662199160464, "tag": "clear"}, {"confidence":
|
76
|
+
25.820873793123134, "tag": "sunny"}, {"confidence": 25.249273427789486, "tag":
|
77
|
+
"environment"}, {"confidence": 24.784280134829594, "tag": "grow"}, {"confidence":
|
78
|
+
23.88433734658078, "tag": "lea"}, {"confidence": 22.817978658602602, "tag":
|
79
|
+
"heavens"}, {"confidence": 22.44027106067515, "tag": "fields"}, {"confidence":
|
80
|
+
20.938511668812538, "tag": "crop"}, {"confidence": 20.517706843832737, "tag":
|
81
|
+
"tree"}, {"confidence": 20.447862153273224, "tag": "hill"}, {"confidence":
|
82
|
+
19.569563944816185, "tag": "wheat"}, {"confidence": 18.95546129827166, "tag":
|
83
|
+
"terrain"}, {"confidence": 17.955057716039118, "tag": "vista"}, {"confidence":
|
84
|
+
17.569450835012315, "tag": "natural"}, {"confidence": 16.839565788995255,
|
85
|
+
"tag": "afield"}, {"confidence": 16.459624476766944, "tag": "vegetation"},
|
86
|
+
{"confidence": 15.606262365776901, "tag": "autumn"}, {"confidence": 14.824652456724683,
|
87
|
+
"tag": "idyllic"}, {"confidence": 14.77136843227496, "tag": "colorful"}, {"confidence":
|
88
|
+
14.384957278644983, "tag": "morning"}, {"confidence": 14.367668048762654,
|
89
|
+
"tag": "day"}, {"confidence": 13.809386567252993, "tag": "fall"}, {"confidence":
|
90
|
+
13.716099517080783, "tag": "fresh"}, {"confidence": 13.018698186011076, "tag":
|
91
|
+
"springtime"}, {"confidence": 13.014281167627434, "tag": "outdoors"}, {"confidence":
|
92
|
+
12.492227715456595, "tag": "grass land"}, {"confidence": 12.391919022056795,
|
93
|
+
"tag": "wind"}, {"confidence": 11.61768420721705, "tag": "paradise"}, {"confidence":
|
94
|
+
11.274652799211944, "tag": "bright"}, {"confidence": 11.1199590355834, "tag":
|
95
|
+
"farmland"}, {"confidence": 10.974807952034528, "tag": "flora"}, {"confidence":
|
96
|
+
10.329167846181567, "tag": "wallpaper"}, {"confidence": 10.283357516314965,
|
97
|
+
"tag": "space"}, {"confidence": 10.2355123162865, "tag": "tranquil"}, {"confidence":
|
98
|
+
10.213637462208416, "tag": "panoramic"}, {"confidence": 9.940362112755183,
|
99
|
+
"tag": "cereal"}, {"confidence": 9.292821274699154, "tag": "savanna"}, {"confidence":
|
100
|
+
9.271194116375627, "tag": "flower"}, {"confidence": 8.997093005680965, "tag":
|
101
|
+
"forest"}, {"confidence": 8.741998121517126, "tag": "idyll"}, {"confidence":
|
102
|
+
8.019050691498952, "tag": "color"}, {"confidence": 7.917104778874119, "tag":
|
103
|
+
"yellow"}, {"confidence": 7.878111616711064, "tag": "mountain"}, {"confidence":
|
104
|
+
7.671390179151772, "tag": "non urban"}, {"confidence": 7.411188275607708,
|
105
|
+
"tag": "sunrise"}, {"confidence": 7.209431466946387, "tag": "wood"}, {"confidence":
|
106
|
+
7.16812985542264, "tag": "park"}]}]}'
|
87
107
|
http_version:
|
88
|
-
recorded_at:
|
89
|
-
recorded_with: VCR
|
108
|
+
recorded_at: Thu, 15 Dec 2016 19:36:37 GMT
|
109
|
+
recorded_with: VCR 3.0.3
|
@@ -2,13 +2,15 @@
|
|
2
2
|
http_interactions:
|
3
3
|
- request:
|
4
4
|
method: get
|
5
|
-
uri: https://api.imagga.com/v1/tagging?url=http://static.ddmcdn.com/
|
5
|
+
uri: https://api.imagga.com/v1/tagging?url=http://static.ddmcdn.com/NOT_REAL.jpg
|
6
6
|
body:
|
7
7
|
encoding: US-ASCII
|
8
8
|
string: ''
|
9
9
|
headers:
|
10
10
|
User-Agent:
|
11
|
-
- Faraday v0.
|
11
|
+
- Faraday v0.10.0
|
12
|
+
Authorization:
|
13
|
+
- Basic YWNjX2QzNTU2ZmJmMGY4NjdiNTpiNTFmOTgxYzM4ZTVlZTE0ZTVhYjM0ZmEzNjQwNGY3Mg==
|
12
14
|
Accept-Encoding:
|
13
15
|
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
16
|
Accept:
|
@@ -29,19 +31,26 @@ http_interactions:
|
|
29
31
|
Content-Type:
|
30
32
|
- application/json
|
31
33
|
Date:
|
32
|
-
-
|
34
|
+
- Thu, 15 Dec 2016 19:36:38 GMT
|
35
|
+
Monthly-Limit:
|
36
|
+
- '2000'
|
37
|
+
Monthly-Limit-Remaining:
|
38
|
+
- '1994'
|
39
|
+
Monthly-Limit-Reset:
|
40
|
+
- '1484507658'
|
33
41
|
Server:
|
34
|
-
- nginx/1.
|
42
|
+
- nginx/1.9.15
|
35
43
|
Set-Cookie:
|
36
|
-
- session=
|
37
|
-
|
44
|
+
- session=eyJyZXF1ZXN0X2lkIjpudWxsfQ.CzSCRg.m_aET9ENdOrwIxhVX2CNZJ3imag; HttpOnly;
|
45
|
+
Path=/
|
38
46
|
Content-Length:
|
39
|
-
- '
|
47
|
+
- '147'
|
40
48
|
Connection:
|
41
49
|
- keep-alive
|
42
50
|
body:
|
43
51
|
encoding: UTF-8
|
44
|
-
string: '{"results":[],"unsuccessful":[{"image":"
|
52
|
+
string: '{"results": [], "unsuccessful": [{"image": "http://static.ddmcdn.com/NOT_REAL.jpg",
|
53
|
+
"message": "Could not download URL. Request status code 404"}]}'
|
45
54
|
http_version:
|
46
|
-
recorded_at:
|
47
|
-
recorded_with: VCR
|
55
|
+
recorded_at: Thu, 15 Dec 2016 19:36:38 GMT
|
56
|
+
recorded_with: VCR 3.0.3
|
@@ -1,50 +1,46 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
context "client" do
|
6
|
-
|
3
|
+
describe 'An Imagga Auto Tag API' do
|
4
|
+
context 'client' do
|
7
5
|
before(:each) do
|
8
6
|
@client = ImaggaAutoTag::Client.new(ENV['IMAGGA_API_KEY'], ENV['IMAGGA_API_SECRET'])
|
9
7
|
end
|
10
8
|
|
11
|
-
it
|
9
|
+
it 'connects' do
|
12
10
|
VCR.use_cassette('image') do
|
13
|
-
expect
|
14
|
-
results = @client.fetch(
|
15
|
-
|
11
|
+
expect do
|
12
|
+
results = @client.fetch('http://static.ddmcdn.com/gif/landscape-photography-1.jpg')
|
13
|
+
end.not_to raise_error
|
16
14
|
end
|
17
15
|
end
|
18
|
-
|
19
16
|
end
|
20
17
|
|
21
|
-
context
|
22
|
-
|
18
|
+
context 'successful result' do
|
23
19
|
before do
|
24
20
|
VCR.use_cassette('image') do
|
25
21
|
@client = ImaggaAutoTag::Client.new(ENV['IMAGGA_API_KEY'], ENV['IMAGGA_API_SECRET'])
|
26
|
-
@results = @client.fetch(
|
22
|
+
@results = @client.fetch('http://static.ddmcdn.com/gif/landscape-photography-1.jpg')
|
27
23
|
end
|
28
24
|
end
|
29
25
|
|
30
|
-
it
|
26
|
+
it 'returns a tagged image object' do
|
31
27
|
expect(@results).to be_an_instance_of(ImaggaAutoTag::TaggedImage)
|
32
28
|
end
|
33
29
|
|
34
|
-
it
|
30
|
+
it 'has a status code' do
|
35
31
|
expect(@results.status).to be 200
|
36
32
|
end
|
37
33
|
|
38
|
-
it
|
34
|
+
it 'has tags' do
|
39
35
|
expect(@results.tags[0]).to be_an_instance_of(ImaggaAutoTag::Tag)
|
40
36
|
end
|
41
37
|
|
42
|
-
it
|
38
|
+
it 'has tags with a confidence and name' do
|
43
39
|
expect(@results.tags[0].name).to be_an_instance_of(String)
|
44
40
|
expect(@results.tags[0].confidence).to be_an_instance_of(Float)
|
45
41
|
end
|
46
42
|
|
47
|
-
it
|
43
|
+
it 'drops tags under a certain threshold if scrubbed' do
|
48
44
|
number_of_tags = @results.tags.size
|
49
45
|
|
50
46
|
@results.scrub
|
@@ -52,37 +48,78 @@ describe "An Imagga Auto Tag API" do
|
|
52
48
|
expect(@results.tags.size).to be < number_of_tags
|
53
49
|
end
|
54
50
|
|
55
|
-
it
|
51
|
+
it 'converts tags into a comma delimitted string' do
|
56
52
|
expect(@results.to_csv).to be_an_instance_of(String)
|
57
53
|
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'results with error' do
|
57
|
+
before do
|
58
|
+
@test = Faraday.new do |builder|
|
59
|
+
builder.adapter :test do |stub|
|
60
|
+
stub.get('http://static.ddmcdn.com/gif/landscape-photography-1.jpg') do |_env|
|
61
|
+
[403, {}, '{
|
62
|
+
"status": "error",
|
63
|
+
"message": "You have reached your monthly limits for this subscription.",
|
64
|
+
"type": "monthly_limit_reached"
|
65
|
+
}']
|
66
|
+
end
|
67
|
+
stub.get('http://static.ddmcdn.com/gif/landscape-photography-2.jpg') do |_env|
|
68
|
+
[403, {}, '{
|
69
|
+
"status": "error",
|
70
|
+
"message": "You have reached your monthly limits for this subscription."
|
71
|
+
}']
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'raise an imagga error' do
|
78
|
+
resp = @test.get('http://static.ddmcdn.com/gif/landscape-photography-1.jpg')
|
79
|
+
|
80
|
+
expect { ImaggaAutoTag::TaggedImage.new(resp) }.to raise_error ImaggaAutoTag::ImaggaError,
|
81
|
+
'You have reached your monthly limits for this subscription.'
|
82
|
+
end
|
58
83
|
|
84
|
+
it 'contains stirng as an error type' do
|
85
|
+
resp = @test.get('http://static.ddmcdn.com/gif/landscape-photography-1.jpg')
|
86
|
+
|
87
|
+
expect { ImaggaAutoTag::TaggedImage.new(resp) }.to raise_error do |error|
|
88
|
+
expect(error.type).to eq 'monthly_limit_reached'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'contains nil as an error type' do
|
93
|
+
resp = @test.get('http://static.ddmcdn.com/gif/landscape-photography-2.jpg')
|
94
|
+
|
95
|
+
expect { ImaggaAutoTag::TaggedImage.new(resp) }.to raise_error do |error|
|
96
|
+
expect(error.type).to eq nil
|
97
|
+
end
|
98
|
+
end
|
59
99
|
end
|
60
100
|
|
61
|
-
context
|
62
|
-
|
101
|
+
context 'could not download image' do
|
63
102
|
before do
|
64
103
|
VCR.use_cassette('no_download') do
|
65
104
|
@client = ImaggaAutoTag::Client.new(ENV['IMAGGA_API_KEY'], ENV['IMAGGA_API_SECRET'])
|
66
|
-
@results = @client.fetch(
|
105
|
+
@results = @client.fetch('http://static.ddmcdn.com/NOT_REAL.jpg')
|
67
106
|
end
|
68
107
|
end
|
69
108
|
|
70
|
-
it
|
109
|
+
it 'returns a tagged image object' do
|
71
110
|
expect(@results).to be_an_instance_of(ImaggaAutoTag::TaggedImage)
|
72
111
|
end
|
73
112
|
|
74
|
-
it
|
113
|
+
it 'has a status code' do
|
75
114
|
expect(@results.status).to be 200
|
76
115
|
end
|
77
116
|
|
78
|
-
it
|
117
|
+
it 'does not have tags' do
|
79
118
|
expect(@results.tags).to be_empty
|
80
119
|
end
|
81
120
|
|
82
|
-
it
|
83
|
-
expect(@results.to_csv).to eq
|
121
|
+
it 'csv is empty string' do
|
122
|
+
expect(@results.to_csv).to eq ''
|
84
123
|
end
|
85
|
-
|
86
124
|
end
|
87
|
-
|
88
|
-
end
|
125
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luke Chesser
|
8
|
+
- Unsplash Team
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2017-01-12 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -110,13 +111,14 @@ dependencies:
|
|
110
111
|
version: '0'
|
111
112
|
description:
|
112
113
|
email:
|
113
|
-
-
|
114
|
+
- dev@unsplash.com
|
114
115
|
executables: []
|
115
116
|
extensions: []
|
116
117
|
extra_rdoc_files: []
|
117
118
|
files:
|
118
119
|
- ".gitignore"
|
119
120
|
- ".rspec"
|
121
|
+
- ".travis.yml"
|
120
122
|
- Gemfile
|
121
123
|
- LICENSE.txt
|
122
124
|
- README.md
|
@@ -124,6 +126,7 @@ files:
|
|
124
126
|
- imagga_auto_tag.gemspec
|
125
127
|
- lib/imagga_auto_tag.rb
|
126
128
|
- lib/imagga_auto_tag/client.rb
|
129
|
+
- lib/imagga_auto_tag/imagga_error.rb
|
127
130
|
- lib/imagga_auto_tag/tag.rb
|
128
131
|
- lib/imagga_auto_tag/tagged_image.rb
|
129
132
|
- lib/imagga_auto_tag/version.rb
|
@@ -131,7 +134,7 @@ files:
|
|
131
134
|
- spec/cassettes/no_download.yml
|
132
135
|
- spec/imagga_auto_tag_spec.rb
|
133
136
|
- spec/spec_helper.rb
|
134
|
-
homepage:
|
137
|
+
homepage: https://github.com/crewlabs/imagga_auto_tag/
|
135
138
|
licenses:
|
136
139
|
- MIT
|
137
140
|
metadata: {}
|
@@ -151,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
154
|
version: '0'
|
152
155
|
requirements: []
|
153
156
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.6.8
|
155
158
|
signing_key:
|
156
159
|
specification_version: 4
|
157
160
|
summary: Simple wrapper around the Imagga Auto Tagging API
|