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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8c6708793a0b4cfc8933fe55e7a14976725b1ce
4
- data.tar.gz: 237191d725152c0c03f95093ae9a3ffc08e7d39e
3
+ metadata.gz: 6bb074258516adf42ee4a2434db608e2bec9336e
4
+ data.tar.gz: cddc582944f2b5b320161645c191b2019b50dbd5
5
5
  SHA512:
6
- metadata.gz: 2e6eb7125ae2722c7981262e03a1e00da0b3d4ed8815d3815c68afb305b0e6af9ec5de7df02f5165e5b16348111d57c677eaca881dfb5de400a80941e0d047a9
7
- data.tar.gz: e2b0e4142582bf83807357a1ce54392cfda484f2f60bea6cc166203417695074802a3bf617472bde07ae61223e1ccdfd691075b19a6ef9e9dff4ab47c1aed5e0
6
+ metadata.gz: 951340b44400168408357e7f32407f4f96c61648c8d6d68b0cb5f7bfddc75d36938a1094a2240668a988e41d4fd65865460d3fd887ca264db95c241b4447a5f8
7
+ data.tar.gz: 41586d21ed38f6ad95cbb10ec9cb70db22b5e044d321eb62577f8ba9d65c1315cea130c48160fb1a92043897378af9e9e0808940e7f862465a92f51fd14c1dc4
data/.gitignore CHANGED
@@ -12,4 +12,5 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
- .env
15
+ .env
16
+ *.gem
@@ -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/lukechesser/imagga_auto_tag/fork )
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
- require "bundler/gem_tasks"
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
@@ -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 = "imagga_auto_tag"
7
+ spec.name = 'imagga_auto_tag'
8
8
  spec.version = ImaggaAutoTag::VERSION
9
- spec.authors = ["Luke Chesser"]
10
- spec.email = ["luke@unsplash.com"]
11
- spec.summary = %q{Simple wrapper around the Imagga Auto Tagging API}
12
- spec.homepage = ""
13
- spec.license = "MIT"
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 = ["lib"]
18
+ spec.require_paths = ['lib']
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.7"
21
- spec.add_development_dependency "rake", "~> 10.0"
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
22
 
23
- spec.add_development_dependency "rspec"
24
- spec.add_development_dependency "vcr"
25
- spec.add_development_dependency "webmock"
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'vcr'
25
+ spec.add_development_dependency 'webmock'
26
26
 
27
- spec.add_dependency "faraday"
28
- spec.add_dependency "json"
27
+ spec.add_dependency 'faraday'
28
+ spec.add_dependency 'json'
29
29
  end
@@ -1,6 +1,7 @@
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"
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
- IMAGGA_API_BASE_URL = "https://api.imagga.com"
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, {url: url}
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
@@ -0,0 +1,11 @@
1
+ module ImaggaAutoTag
2
+ class ImaggaError < StandardError
3
+ attr_reader :type
4
+
5
+ # Initiliaze a new imagga error.
6
+ # Can contain the error typw
7
+ def initialize(error_type)
8
+ @type = error_type
9
+ end
10
+ end
11
+ end
@@ -1,14 +1,10 @@
1
1
  module ImaggaAutoTag
2
-
3
2
  class Tag
4
-
5
3
  attr_reader :confidence, :name
6
4
 
7
5
  def initialize(raw_data)
8
6
  @confidence = raw_data['confidence']
9
7
  @name = raw_data['tag']
10
8
  end
11
-
12
9
  end
13
-
14
- end
10
+ end
@@ -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
- @tags = []
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
@@ -1,3 +1,3 @@
1
1
  module ImaggaAutoTag
2
- VERSION = "0.2.1"
2
+ VERSION = '0.2.2'.freeze
3
3
  end
@@ -8,7 +8,9 @@ http_interactions:
8
8
  string: ''
9
9
  headers:
10
10
  User-Agent:
11
- - Faraday v0.9.1
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
- - Wed, 06 May 2015 19:44:17 GMT
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.4.6 (Ubuntu)
42
+ - nginx/1.9.15
35
43
  Set-Cookie:
36
- - session=eyJyZXF1ZXN0X2lkIjp7IiBiIjoiTXpRM09EcGhZMk5mT0Raa016WmxZamM0WXpBMFl6TXcifX0.CCwAkQ.8QdcpHTw7p_0cKyNo2s5Sp-PE50;
37
- HttpOnly; Path=/
44
+ - session=eyJyZXF1ZXN0X2lkIjpudWxsfQ.CzSCRQ.r1ozqTn3jf1Tvh004O5nlUPPIy4; HttpOnly;
45
+ Path=/
38
46
  Content-Length:
39
- - '3394'
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": 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"}]}]}'
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: Wed, 06 May 2015 19:43:07 GMT
89
- recorded_with: VCR 2.9.3
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/gif/landscape-photography-1.jpg
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.9.1
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
- - Wed, 06 May 2015 19:44:17 GMT
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.4.6 (Ubuntu)
42
+ - nginx/1.9.15
35
43
  Set-Cookie:
36
- - session=eyJyZXF1ZXN0X2lkIjp7IiBiIjoiTXpRM09EcGhZMk5mT0Raa016WmxZamM0WXpBMFl6TXcifX0.CCwAkQ.8QdcpHTw7p_0cKyNo2s5Sp-PE50;
37
- HttpOnly; Path=/
44
+ - session=eyJyZXF1ZXN0X2lkIjpudWxsfQ.CzSCRg.m_aET9ENdOrwIxhVX2CNZJ3imag; HttpOnly;
45
+ Path=/
38
46
  Content-Length:
39
- - '184'
47
+ - '147'
40
48
  Connection:
41
49
  - keep-alive
42
50
  body:
43
51
  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."}]}'
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: Wed, 06 May 2015 19:43:07 GMT
47
- recorded_with: VCR 2.9.3
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 "An Imagga Auto Tag API" do
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 "connects" do
9
+ it 'connects' do
12
10
  VCR.use_cassette('image') do
13
- expect {
14
- results = @client.fetch("http://static.ddmcdn.com/gif/landscape-photography-1.jpg")
15
- }.not_to raise_error
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 "successful result" do
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("http://static.ddmcdn.com/gif/landscape-photography-1.jpg")
22
+ @results = @client.fetch('http://static.ddmcdn.com/gif/landscape-photography-1.jpg')
27
23
  end
28
24
  end
29
25
 
30
- it "returns a tagged image object" do
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 "has a status code" do
30
+ it 'has a status code' do
35
31
  expect(@results.status).to be 200
36
32
  end
37
33
 
38
- it "has tags" do
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 "has tags with a confidence and name" do
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 "drops tags under a certain threshold if scrubbed" do
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 "converts tags into a comma delimitted string" do
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 "could not download image" do
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("http://static.ddmcdn.com/gif/landscape-photography-1.jpg")
105
+ @results = @client.fetch('http://static.ddmcdn.com/NOT_REAL.jpg')
67
106
  end
68
107
  end
69
108
 
70
- it "returns a tagged image object" do
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 "has a status code" do
113
+ it 'has a status code' do
75
114
  expect(@results.status).to be 200
76
115
  end
77
116
 
78
- it "does not have tags" do
117
+ it 'does not have tags' do
79
118
  expect(@results.tags).to be_empty
80
119
  end
81
120
 
82
- it "csv is empty string" do
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
@@ -10,4 +10,4 @@ end
10
10
 
11
11
  RSpec.configure do |c|
12
12
  c.mock_with :rspec
13
- end
13
+ end
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.1
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: 2015-05-06 00:00:00.000000000 Z
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
- - luke@unsplash.com
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.2.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