imagga 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/README.md +28 -1
- data/imagga.gemspec +1 -0
- data/lib/imagga.rb +8 -3
- data/lib/imagga/client.rb +12 -34
- data/lib/imagga/commands.rb +42 -0
- data/lib/imagga/core_client.rb +25 -0
- data/lib/imagga/exceptions.rb +3 -0
- data/lib/imagga/image.rb +59 -2
- data/lib/imagga/image_or_url_parametizer.rb +21 -0
- data/lib/imagga/options.rb +74 -0
- data/lib/imagga/parametizer.rb +18 -0
- data/lib/imagga/rank_color_parametizer.rb +17 -0
- data/lib/imagga/resolution_parametizer.rb +17 -0
- data/lib/imagga/result_builder.rb +27 -0
- data/lib/imagga/version.rb +1 -1
- data/spec/fixtures/crop_response.txt +62 -0
- data/spec/fixtures/extract_response.txt +253 -0
- data/spec/fixtures/rank_response.txt +12 -0
- data/spec/integration/crop_spec.rb +60 -0
- data/spec/integration/extract_spec.rb +51 -0
- data/spec/integration/rank_spec.rb +103 -0
- data/spec/lib/commands_spec.rb +70 -0
- data/spec/lib/core_client_spec.rb +43 -0
- data/spec/lib/crop_info_spec.rb +15 -0
- data/spec/lib/crop_options_spec.rb +24 -0
- data/spec/lib/crop_result_builder_spec.rb +4 -0
- data/spec/lib/extraction_options_spec.rb +16 -51
- data/spec/lib/image_crop_spec.rb +34 -0
- data/spec/lib/image_or_url_parametizer_spec.rb +65 -0
- data/spec/lib/parametizer_spec.rb +42 -0
- data/spec/lib/rank_color_parametizer_spec.rb +27 -0
- data/spec/lib/rank_color_spec.rb +51 -0
- data/spec/lib/rank_options_spec.rb +28 -0
- data/spec/lib/rank_result_builder_spec.rb +1 -12
- data/spec/lib/resolution_parametizer_spec.rb +60 -0
- metadata +63 -28
- data/lib/imagga/extract_options.rb +0 -74
- data/lib/imagga/extract_result_builder.rb +0 -11
- data/lib/imagga/rank_result_builder.rb +0 -9
- data/spec/lib/client_spec.rb +0 -352
| @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class DummyParametizer; include Imagga::Parametizer; end
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            describe Imagga::Parametizer do
         | 
| 6 | 
            +
              subject { DummyParametizer.new }
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              describe "#build_comma_separated_string" do
         | 
| 9 | 
            +
                it "builds list of object fields" do
         | 
| 10 | 
            +
                  object = stub(field: 'asdf')
         | 
| 11 | 
            +
                  subject.build_comma_separated_string([object]*2, :field).should == 'asdf,asdf'
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                it "defaults to default value, if field is not present" do
         | 
| 15 | 
            +
                  object = Object.new
         | 
| 16 | 
            +
                  object2 = stub(field: 'asdf')
         | 
| 17 | 
            +
                  subject.build_comma_separated_string([object, object2], :field, 'qwer').should == 'qwer,asdf'
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                it "produces no result if all items default to the default value" do
         | 
| 21 | 
            +
                  object = Object.new
         | 
| 22 | 
            +
                  subject.build_comma_separated_string([object]*3, :field, 'qwer').should == nil
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              describe "#build_boolean_options" do
         | 
| 27 | 
            +
                it "produces hash with boolean values coded as 1 and 0" do
         | 
| 28 | 
            +
                  input = { foo: true, boo: false }
         | 
| 29 | 
            +
                  subject.build_boolean_options(input, [:foo, :boo]).should ==  { foo: 1, boo: 0 }
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                it "produces hash with initial boolean values '1' and '0' coded as 1 and 0" do
         | 
| 33 | 
            +
                  input = { foo: '1', boo: '0' }
         | 
| 34 | 
            +
                  subject.build_boolean_options(input, [:foo, :boo]).should ==  { foo: 1, boo: 0 }
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                it "produces hash with initial boolean values 1 and 0 coded as 1 and 0" do
         | 
| 38 | 
            +
                  input = { foo: 1, boo: 0 }
         | 
| 39 | 
            +
                  subject.build_boolean_options(input, [:foo, :boo]).should ==  { foo: 1, boo: 0 }
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Imagga::RankColorParametizer do
         | 
| 4 | 
            +
              subject { described_class.new }
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              describe "#parametrize" do
         | 
| 7 | 
            +
                it "generates string presentation of the rank color object" do
         | 
| 8 | 
            +
                  subject.parametrize(Imagga::RankColor.new(percent: 40, hex: '#123456')).should == { color_vector: '40,18,52,86' }
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                it "generates string presentation of many rank color objects" do
         | 
| 12 | 
            +
                  subject.parametrize([
         | 
| 13 | 
            +
                    Imagga::RankColor.new(percent: 40, hex: '#123456'),
         | 
| 14 | 
            +
                    Imagga::RankColor.new(percent: 10, hex: '#23421e'),
         | 
| 15 | 
            +
                    Imagga::RankColor.new(percent: 33, hex: '#09238f')
         | 
| 16 | 
            +
                  ]).should == { color_vector: '40,18,52,86,10,35,66,30,33,9,35,143' }
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                it "does not change the given color vector string" do
         | 
| 20 | 
            +
                  subject.parametrize([
         | 
| 21 | 
            +
                    Imagga::RankColor.new(percent: 40, hex: '#123456'),
         | 
| 22 | 
            +
                    '10,35,66,30',
         | 
| 23 | 
            +
                    Imagga::RankColor.new(percent: 33, hex: '#09238f')
         | 
| 24 | 
            +
                  ]).should == { color_vector: '40,18,52,86,10,35,66,30,33,9,35,143' }
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Imagga::RankColor do
         | 
| 4 | 
            +
              context "when initialized through rgb values" do
         | 
| 5 | 
            +
                subject { described_class.new(percent: 40, r: 200, g: 100, b: 50) } 
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                it "has percent" do
         | 
| 8 | 
            +
                  subject.percent.should == 40
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                it "has r value" do
         | 
| 12 | 
            +
                  subject.r.should == 200
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                it "has g value" do
         | 
| 16 | 
            +
                  subject.g.should == 100
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                it "has b value" do
         | 
| 20 | 
            +
                  subject.b.should == 50
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                it "has hex value" do
         | 
| 24 | 
            +
                  subject.hex.should == '#c86432'
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              context "when initialized through hex value" do
         | 
| 29 | 
            +
                subject { described_class.new(percent: 40, hex: '#c86432') } 
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                it "has percent" do
         | 
| 32 | 
            +
                  subject.percent.should == 40
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                it "has r value" do
         | 
| 36 | 
            +
                  subject.r.should == 200
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                it "has g value" do
         | 
| 40 | 
            +
                  subject.g.should == 100
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                it "has b value" do
         | 
| 44 | 
            +
                  subject.b.should == 50
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                it "has hex value" do
         | 
| 48 | 
            +
                  subject.hex.should == '#c86432'
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
              end
         | 
| 51 | 
            +
            end
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Imagga::RankOptions do
         | 
| 4 | 
            +
              subject { described_class.new('apikey', 'secret') }
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              describe "#options" do
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                it "builds options" do
         | 
| 9 | 
            +
                  subject.options(
         | 
| 10 | 
            +
                    color_vector:  '49,33,44,55,11,22,33,44',
         | 
| 11 | 
            +
                    urls:           'http://image',
         | 
| 12 | 
            +
                    type:           :object,
         | 
| 13 | 
            +
                    dist:           3000,
         | 
| 14 | 
            +
                    count:          10
         | 
| 15 | 
            +
                  ).should == {
         | 
| 16 | 
            +
                    api_key:      'apikey',
         | 
| 17 | 
            +
                    color_vector: '49,33,44,55,11,22,33,44',
         | 
| 18 | 
            +
                    count:        '10',
         | 
| 19 | 
            +
                    dist:         '3000',
         | 
| 20 | 
            +
                    method:       'imagga.colorsearch.rank',
         | 
| 21 | 
            +
                    sig:          '96185035e02a781a7b3455eb500eeec9',
         | 
| 22 | 
            +
                    type:         'object',
         | 
| 23 | 
            +
                    urls:         'http://image',
         | 
| 24 | 
            +
                    v:            '1.0'
         | 
| 25 | 
            +
                  }
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| @@ -1,18 +1,7 @@ | |
| 1 1 | 
             
            require 'spec_helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            describe Imagga::RankResultBuilder do
         | 
| 4 | 
            -
              let(:result) {  | 
| 5 | 
            -
                'rank_similarity' =>  [
         | 
| 6 | 
            -
                  {
         | 
| 7 | 
            -
                    "id" => 8774077,
         | 
| 8 | 
            -
                    "dist" => 2597.38299
         | 
| 9 | 
            -
                  },
         | 
| 10 | 
            -
                  {
         | 
| 11 | 
            -
                    "id" => 9085916,
         | 
| 12 | 
            -
                    "dist" => 2681.33259
         | 
| 13 | 
            -
                  }
         | 
| 14 | 
            -
                ]
         | 
| 15 | 
            -
              } }
         | 
| 4 | 
            +
              let(:result) { JSON.parse(IO.read('./spec/fixtures/rank_response.txt')) }
         | 
| 16 5 |  | 
| 17 6 | 
             
              subject { described_class.new }
         | 
| 18 7 |  | 
| @@ -0,0 +1,60 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Imagga::ResolutionParametizer do
         | 
| 4 | 
            +
              subject { described_class.new }
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              describe "#parametrize" do
         | 
| 7 | 
            +
                it "creates a resolutions parameter for the service" do
         | 
| 8 | 
            +
                  subject.parametrize('123x342').should == { resolutions: '123,342' }
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              describe "#build_resolutions" do
         | 
| 13 | 
            +
                it "produces empty string from nil input" do
         | 
| 14 | 
            +
                  subject.build_resolutions(nil).should ==  ''
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                it "produces empty string from empty string input" do
         | 
| 18 | 
            +
                  subject.build_resolutions('').should ==  ''
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                it "produces empty string from empty array" do
         | 
| 22 | 
            +
                  subject.build_resolutions([]).should ==  ''
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                it "produces comma separated string from single a x b resolution string" do
         | 
| 26 | 
            +
                  subject.build_resolutions('123x234').should ==  '123,234'
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                it "produces comma separated string from many a x b resolutions in one string" do
         | 
| 30 | 
            +
                  subject.build_resolutions('123x234,90x33,432x88').should ==  '123,234,90,33,432,88'
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                it "leaves comma seperated resolution as is" do
         | 
| 34 | 
            +
                  subject.build_resolutions('123,234').should ==  '123,234'
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                it "produces comma separated string from single element a x b resolution array" do
         | 
| 38 | 
            +
                  subject.build_resolutions(['123x234']).should ==  '123,234'
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                it "produces comma separated string from many a x b resolutions in one array" do
         | 
| 42 | 
            +
                  subject.build_resolutions(['123x234','90x33','432x88']).should ==  '123,234,90,33,432,88'
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                it "produces comma separated string from mixed format array" do
         | 
| 46 | 
            +
                  subject.build_resolutions(['123x234,90,33','432x88']).should ==  '123,234,90,33,432,88'
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              describe "#build_resolution_string" do
         | 
| 51 | 
            +
                it "translates a x b resolution form to comma seperated string" do
         | 
| 52 | 
            +
                  subject.build_resolution_string('123x234').should ==  '123,234'
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                it "leaves comma seperated resolution as is" do
         | 
| 56 | 
            +
                  subject.build_resolution_string('123,234').should ==  '123,234'
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
            end
         | 
| 60 | 
            +
             | 
    
        metadata
    CHANGED
    
    | @@ -1,20 +1,18 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: imagga
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 5 | 
            -
              prerelease: 
         | 
| 4 | 
            +
              version: 0.0.5
         | 
| 6 5 | 
             
            platform: ruby
         | 
| 7 6 | 
             
            authors:
         | 
| 8 7 | 
             
            - Mart Karu
         | 
| 9 8 | 
             
            autorequire: 
         | 
| 10 9 | 
             
            bindir: bin
         | 
| 11 10 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2013- | 
| 11 | 
            +
            date: 2013-04-06 00:00:00.000000000 Z
         | 
| 13 12 | 
             
            dependencies:
         | 
| 14 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 14 | 
             
              name: httparty
         | 
| 16 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 17 | 
            -
                none: false
         | 
| 18 16 | 
             
                requirements:
         | 
| 19 17 | 
             
                - - ~>
         | 
| 20 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -22,7 +20,6 @@ dependencies: | |
| 22 20 | 
             
              type: :runtime
         | 
| 23 21 | 
             
              prerelease: false
         | 
| 24 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 25 | 
            -
                none: false
         | 
| 26 23 | 
             
                requirements:
         | 
| 27 24 | 
             
                - - ~>
         | 
| 28 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -30,7 +27,6 @@ dependencies: | |
| 30 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 31 28 | 
             
              name: json
         | 
| 32 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 33 | 
            -
                none: false
         | 
| 34 30 | 
             
                requirements:
         | 
| 35 31 | 
             
                - - ~>
         | 
| 36 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -38,15 +34,27 @@ dependencies: | |
| 38 34 | 
             
              type: :runtime
         | 
| 39 35 | 
             
              prerelease: false
         | 
| 40 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 41 | 
            -
                none: false
         | 
| 42 37 | 
             
                requirements:
         | 
| 43 38 | 
             
                - - ~>
         | 
| 44 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 45 40 | 
             
                    version: '1.7'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: color
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ~>
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: 1.4.1
         | 
| 48 | 
            +
              type: :runtime
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ~>
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: 1.4.1
         | 
| 46 55 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 47 56 | 
             
              name: rspec
         | 
| 48 57 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 49 | 
            -
                none: false
         | 
| 50 58 | 
             
                requirements:
         | 
| 51 59 | 
             
                - - ~>
         | 
| 52 60 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -54,7 +62,6 @@ dependencies: | |
| 54 62 | 
             
              type: :development
         | 
| 55 63 | 
             
              prerelease: false
         | 
| 56 64 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            -
                none: false
         | 
| 58 65 | 
             
                requirements:
         | 
| 59 66 | 
             
                - - ~>
         | 
| 60 67 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -62,7 +69,6 @@ dependencies: | |
| 62 69 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 63 70 | 
             
              name: rake
         | 
| 64 71 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 65 | 
            -
                none: false
         | 
| 66 72 | 
             
                requirements:
         | 
| 67 73 | 
             
                - - ! '>='
         | 
| 68 74 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -70,7 +76,6 @@ dependencies: | |
| 70 76 | 
             
              type: :development
         | 
| 71 77 | 
             
              prerelease: false
         | 
| 72 78 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 73 | 
            -
                none: false
         | 
| 74 79 | 
             
                requirements:
         | 
| 75 80 | 
             
                - - ! '>='
         | 
| 76 81 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -78,7 +83,6 @@ dependencies: | |
| 78 83 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 79 84 | 
             
              name: fakeweb
         | 
| 80 85 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 81 | 
            -
                none: false
         | 
| 82 86 | 
             
                requirements:
         | 
| 83 87 | 
             
                - - ! '>='
         | 
| 84 88 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -86,7 +90,6 @@ dependencies: | |
| 86 90 | 
             
              type: :development
         | 
| 87 91 | 
             
              prerelease: false
         | 
| 88 92 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 89 | 
            -
                none: false
         | 
| 90 93 | 
             
                requirements:
         | 
| 91 94 | 
             
                - - ! '>='
         | 
| 92 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| @@ -108,58 +111,90 @@ files: | |
| 108 111 | 
             
            - imagga.gemspec
         | 
| 109 112 | 
             
            - lib/imagga.rb
         | 
| 110 113 | 
             
            - lib/imagga/client.rb
         | 
| 114 | 
            +
            - lib/imagga/commands.rb
         | 
| 115 | 
            +
            - lib/imagga/core_client.rb
         | 
| 111 116 | 
             
            - lib/imagga/exceptions.rb
         | 
| 112 | 
            -
            - lib/imagga/extract_options.rb
         | 
| 113 | 
            -
            - lib/imagga/extract_result_builder.rb
         | 
| 114 117 | 
             
            - lib/imagga/image.rb
         | 
| 115 | 
            -
            - lib/imagga/ | 
| 118 | 
            +
            - lib/imagga/image_or_url_parametizer.rb
         | 
| 119 | 
            +
            - lib/imagga/options.rb
         | 
| 120 | 
            +
            - lib/imagga/parametizer.rb
         | 
| 121 | 
            +
            - lib/imagga/rank_color_parametizer.rb
         | 
| 122 | 
            +
            - lib/imagga/resolution_parametizer.rb
         | 
| 123 | 
            +
            - lib/imagga/result_builder.rb
         | 
| 116 124 | 
             
            - lib/imagga/version.rb
         | 
| 117 | 
            -
            - spec/ | 
| 125 | 
            +
            - spec/fixtures/crop_response.txt
         | 
| 126 | 
            +
            - spec/fixtures/extract_response.txt
         | 
| 127 | 
            +
            - spec/fixtures/rank_response.txt
         | 
| 128 | 
            +
            - spec/integration/crop_spec.rb
         | 
| 129 | 
            +
            - spec/integration/extract_spec.rb
         | 
| 130 | 
            +
            - spec/integration/rank_spec.rb
         | 
| 131 | 
            +
            - spec/lib/commands_spec.rb
         | 
| 132 | 
            +
            - spec/lib/core_client_spec.rb
         | 
| 133 | 
            +
            - spec/lib/crop_info_spec.rb
         | 
| 134 | 
            +
            - spec/lib/crop_options_spec.rb
         | 
| 135 | 
            +
            - spec/lib/crop_result_builder_spec.rb
         | 
| 118 136 | 
             
            - spec/lib/extract_result_builder_spec.rb
         | 
| 119 137 | 
             
            - spec/lib/extraction_options_spec.rb
         | 
| 120 138 | 
             
            - spec/lib/image_color_spec.rb
         | 
| 139 | 
            +
            - spec/lib/image_crop_spec.rb
         | 
| 121 140 | 
             
            - spec/lib/image_info_spec.rb
         | 
| 141 | 
            +
            - spec/lib/image_or_url_parametizer_spec.rb
         | 
| 122 142 | 
             
            - spec/lib/image_spec.rb
         | 
| 143 | 
            +
            - spec/lib/parametizer_spec.rb
         | 
| 144 | 
            +
            - spec/lib/rank_color_parametizer_spec.rb
         | 
| 145 | 
            +
            - spec/lib/rank_color_spec.rb
         | 
| 146 | 
            +
            - spec/lib/rank_options_spec.rb
         | 
| 123 147 | 
             
            - spec/lib/rank_result_builder_spec.rb
         | 
| 124 148 | 
             
            - spec/lib/rank_similarity_spec.rb
         | 
| 149 | 
            +
            - spec/lib/resolution_parametizer_spec.rb
         | 
| 125 150 | 
             
            - spec/spec_helper.rb
         | 
| 126 151 | 
             
            homepage: ''
         | 
| 127 152 | 
             
            licenses: []
         | 
| 153 | 
            +
            metadata: {}
         | 
| 128 154 | 
             
            post_install_message: 
         | 
| 129 155 | 
             
            rdoc_options: []
         | 
| 130 156 | 
             
            require_paths:
         | 
| 131 157 | 
             
            - lib
         | 
| 132 158 | 
             
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 133 | 
            -
              none: false
         | 
| 134 159 | 
             
              requirements:
         | 
| 135 160 | 
             
              - - ! '>='
         | 
| 136 161 | 
             
                - !ruby/object:Gem::Version
         | 
| 137 162 | 
             
                  version: '0'
         | 
| 138 | 
            -
                  segments:
         | 
| 139 | 
            -
                  - 0
         | 
| 140 | 
            -
                  hash: 1906087538434497145
         | 
| 141 163 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 142 | 
            -
              none: false
         | 
| 143 164 | 
             
              requirements:
         | 
| 144 165 | 
             
              - - ! '>='
         | 
| 145 166 | 
             
                - !ruby/object:Gem::Version
         | 
| 146 167 | 
             
                  version: '0'
         | 
| 147 | 
            -
                  segments:
         | 
| 148 | 
            -
                  - 0
         | 
| 149 | 
            -
                  hash: 1906087538434497145
         | 
| 150 168 | 
             
            requirements: []
         | 
| 151 169 | 
             
            rubyforge_project: 
         | 
| 152 | 
            -
            rubygems_version:  | 
| 170 | 
            +
            rubygems_version: 2.0.3
         | 
| 153 171 | 
             
            signing_key: 
         | 
| 154 | 
            -
            specification_version:  | 
| 172 | 
            +
            specification_version: 4
         | 
| 155 173 | 
             
            summary: Ruby client for accessing Imagga API
         | 
| 156 174 | 
             
            test_files:
         | 
| 157 | 
            -
            - spec/ | 
| 175 | 
            +
            - spec/fixtures/crop_response.txt
         | 
| 176 | 
            +
            - spec/fixtures/extract_response.txt
         | 
| 177 | 
            +
            - spec/fixtures/rank_response.txt
         | 
| 178 | 
            +
            - spec/integration/crop_spec.rb
         | 
| 179 | 
            +
            - spec/integration/extract_spec.rb
         | 
| 180 | 
            +
            - spec/integration/rank_spec.rb
         | 
| 181 | 
            +
            - spec/lib/commands_spec.rb
         | 
| 182 | 
            +
            - spec/lib/core_client_spec.rb
         | 
| 183 | 
            +
            - spec/lib/crop_info_spec.rb
         | 
| 184 | 
            +
            - spec/lib/crop_options_spec.rb
         | 
| 185 | 
            +
            - spec/lib/crop_result_builder_spec.rb
         | 
| 158 186 | 
             
            - spec/lib/extract_result_builder_spec.rb
         | 
| 159 187 | 
             
            - spec/lib/extraction_options_spec.rb
         | 
| 160 188 | 
             
            - spec/lib/image_color_spec.rb
         | 
| 189 | 
            +
            - spec/lib/image_crop_spec.rb
         | 
| 161 190 | 
             
            - spec/lib/image_info_spec.rb
         | 
| 191 | 
            +
            - spec/lib/image_or_url_parametizer_spec.rb
         | 
| 162 192 | 
             
            - spec/lib/image_spec.rb
         | 
| 193 | 
            +
            - spec/lib/parametizer_spec.rb
         | 
| 194 | 
            +
            - spec/lib/rank_color_parametizer_spec.rb
         | 
| 195 | 
            +
            - spec/lib/rank_color_spec.rb
         | 
| 196 | 
            +
            - spec/lib/rank_options_spec.rb
         | 
| 163 197 | 
             
            - spec/lib/rank_result_builder_spec.rb
         | 
| 164 198 | 
             
            - spec/lib/rank_similarity_spec.rb
         | 
| 199 | 
            +
            - spec/lib/resolution_parametizer_spec.rb
         | 
| 165 200 | 
             
            - spec/spec_helper.rb
         | 
| @@ -1,74 +0,0 @@ | |
| 1 | 
            -
            module Imagga
         | 
| 2 | 
            -
              class BaseOptions
         | 
| 3 | 
            -
                attr_accessor :api_key, :api_secret
         | 
| 4 | 
            -
             | 
| 5 | 
            -
                def initialize(api_key, api_secret)
         | 
| 6 | 
            -
                  @version    = '1.0'
         | 
| 7 | 
            -
                  @api_key    = api_key    || raise_missing(:api_key)
         | 
| 8 | 
            -
                  @api_secret = api_secret || raise_missing(:api_secret)
         | 
| 9 | 
            -
                end
         | 
| 10 | 
            -
             | 
| 11 | 
            -
                def base_options
         | 
| 12 | 
            -
                  { v: @version, api_key: @api_key }
         | 
| 13 | 
            -
                end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
                def sign(options)
         | 
| 16 | 
            -
                  sorted_options_string = options.keys.sort.map do |key|
         | 
| 17 | 
            -
                    "%s=%s" % [key.to_s, options[key]]
         | 
| 18 | 
            -
                  end.join('') << @api_secret
         | 
| 19 | 
            -
                  Digest::MD5.hexdigest(sorted_options_string)
         | 
| 20 | 
            -
                end
         | 
| 21 | 
            -
              end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
              class ExtractOptions < BaseOptions
         | 
| 24 | 
            -
             | 
| 25 | 
            -
                def options(urls_or_images, additional_options={})
         | 
| 26 | 
            -
                  options = base_options.merge(
         | 
| 27 | 
            -
                    method: 'imagga.colorsearch.extract',
         | 
| 28 | 
            -
                    urls: build_urls(urls_or_images),
         | 
| 29 | 
            -
                  )
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                  if ids = build_ids(urls_or_images)
         | 
| 32 | 
            -
                    options.merge!(ids: ids)
         | 
| 33 | 
            -
                  end
         | 
| 34 | 
            -
             | 
| 35 | 
            -
                  [:extract_overall_colors, :extract_object_colors].each do |key|
         | 
| 36 | 
            -
                    if additional_options.keys.include?(key) && (value = additional_options[key] ? 1 : 0)
         | 
| 37 | 
            -
                      options.merge!(key => value)
         | 
| 38 | 
            -
                    end
         | 
| 39 | 
            -
                  end
         | 
| 40 | 
            -
             | 
| 41 | 
            -
                  options.merge!(sig: sign(options))
         | 
| 42 | 
            -
                end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
                def build_urls(urls_or_images)
         | 
| 45 | 
            -
                  [urls_or_images].flatten.map{ |o| o.url rescue o }.join(',')
         | 
| 46 | 
            -
                end
         | 
| 47 | 
            -
             | 
| 48 | 
            -
                def build_ids(urls_or_images)
         | 
| 49 | 
            -
                  ids = [urls_or_images].flatten.map{ |o| o.id rescue 0 }
         | 
| 50 | 
            -
                  return if ids.uniq == [0]
         | 
| 51 | 
            -
                  ids.join(',')
         | 
| 52 | 
            -
                end
         | 
| 53 | 
            -
             | 
| 54 | 
            -
              end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
              class RankOptions < BaseOptions
         | 
| 57 | 
            -
                def options(opts)
         | 
| 58 | 
            -
                  color_vector = opts.fetch(:color_vector)
         | 
| 59 | 
            -
                  type         = opts.fetch(:type)
         | 
| 60 | 
            -
                  dist         = opts.fetch(:dist)
         | 
| 61 | 
            -
                  count        = opts.fetch(:count)
         | 
| 62 | 
            -
             | 
| 63 | 
            -
                  options = base_options.merge(
         | 
| 64 | 
            -
                    method:       'imagga.colorsearch.rank',
         | 
| 65 | 
            -
                    color_vector: color_vector,
         | 
| 66 | 
            -
                    type:         type,
         | 
| 67 | 
            -
                    dist:         dist,
         | 
| 68 | 
            -
                    count:        count
         | 
| 69 | 
            -
                  )
         | 
| 70 | 
            -
             | 
| 71 | 
            -
                  options.merge!(sig: sign(options))
         | 
| 72 | 
            -
                end
         | 
| 73 | 
            -
              end
         | 
| 74 | 
            -
            end
         |