Class: Multitagger::Provider::Imagga
- Inherits:
-
Object
- Object
- Multitagger::Provider::Imagga
- Defined in:
- lib/multitagger/provider/imagga.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ Imagga
constructor
A new instance of Imagga.
- #tag(image) ⇒ Object
Constructor Details
#initialize(config) ⇒ Imagga
Returns a new instance of Imagga.
6 7 8 9 |
# File 'lib/multitagger/provider/imagga.rb', line 6 def initialize(config) @key = config["key"] @secret = config["secret"] end |
Instance Method Details
#tag(image) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/multitagger/provider/imagga.rb', line 11 def tag(image) auth = 'Basic ' + Base64.strict_encode64("#{@key}:#{@secret}").chomp image_response_raw = RestClient.post "https://api.imagga.com/v1/content", { image: File.new(image, 'rb') }, { Authorization: auth } image_response = JSON.parse image_response_raw image_id = image_response["uploaded"].first["id"] tag_response_raw = RestClient.get "https://api.imagga.com/v1/tagging?content=#{image_id}", { Authorization: auth } tag_response = JSON.parse tag_response_raw = tag_response["results"].first["tags"].map { |x| [ x["tag"], x["confidence"] ] } .map { |x| Tag.new(x.first, x.last / .first.last) } end |