turing_api 1.0.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +193 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/turing_api/version.rb +3 -0
- data/lib/turing_api.rb +127 -0
- data/lib/visual_api_exception.rb +2 -0
- data/turing_api.gemspec +38 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aa6c1846c1c5e9e1f03cc1643f49324f64edfca7
|
4
|
+
data.tar.gz: 352244d70243062bfc3a876e4ffa31afe211302b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 357e815a177bc4c82b5278206e3edda45f58bde7172396d273c1ad499228d751fafd5eb52c5847ee60759288bc032d7863d9e200385ec92537d2002ddfe8226c
|
7
|
+
data.tar.gz: 5a090b7381d2a92ff2a951a5e5e8c969abd50a1be9796f3fe97b76222b3d84fe91c24d2c4773946046f79875c6023c9f9d683f235e8ba3a0e35ddaa8b2d02dd1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at harvesh@turingiq.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
byebug (10.0.2)
|
5
|
+
diff-lcs (1.3)
|
6
|
+
httparty (0.16.2)
|
7
|
+
multi_xml (>= 0.5.2)
|
8
|
+
json (2.1.0)
|
9
|
+
multi_xml (0.6.0)
|
10
|
+
rspec (3.7.0)
|
11
|
+
rspec-core (~> 3.7.0)
|
12
|
+
rspec-expectations (~> 3.7.0)
|
13
|
+
rspec-mocks (~> 3.7.0)
|
14
|
+
rspec-core (3.7.1)
|
15
|
+
rspec-support (~> 3.7.0)
|
16
|
+
rspec-expectations (3.7.0)
|
17
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
18
|
+
rspec-support (~> 3.7.0)
|
19
|
+
rspec-mocks (3.7.0)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.7.0)
|
22
|
+
rspec-support (3.7.1)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
byebug
|
29
|
+
httparty (~> 0.16.2)
|
30
|
+
json
|
31
|
+
rspec
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
1.16.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Harvesh Kumar
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,193 @@
|
|
1
|
+
# TuringAPI
|
2
|
+
|
3
|
+
Turing visual search and visually similar recommendations API library for RUBY. The REST API documentation can be found here: [https://api.turingiq.com/doc/](https://api.turingiq.com/doc/)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'turing_api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install turing_api
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Initialize
|
26
|
+
--------
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
#You can initialize the `VisualAPI` class with below parameters.
|
30
|
+
|
31
|
+
api_key = 'your_api_key' # You can get API key when you login at: https://www.turingiq.com/login
|
32
|
+
mode = 'live' # the mode can be either `live` or `sandbox`. Default mode is `live`.
|
33
|
+
@visual = Turing::VisualAPI.new('api_key', 'mode')
|
34
|
+
```
|
35
|
+
|
36
|
+
This library uses namespacing. When instantiating the object, you need to either use the fully qualified namespace:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
@visual = Turing::VisualAPI.new('your_api_key')
|
40
|
+
```
|
41
|
+
|
42
|
+
Or alias it:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
require './lib/VisualAPI'
|
46
|
+
|
47
|
+
@visual = Turing::VisualAPI.new(ENV['your_api_key'])
|
48
|
+
```
|
49
|
+
|
50
|
+
Autocrop
|
51
|
+
--------
|
52
|
+
|
53
|
+
Detect objects in image and get bounding boxes around objects detected.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# image_url is required field.
|
57
|
+
image_url = "https://example.com/image_url.jpg"
|
58
|
+
|
59
|
+
# now let's call the API.
|
60
|
+
resp = @visual.auto_crop(image_url)
|
61
|
+
```
|
62
|
+
|
63
|
+
The bounding boxes returned by this method can be given to visual search to improve visual search quality.
|
64
|
+
|
65
|
+
|
66
|
+
Insert
|
67
|
+
------
|
68
|
+
|
69
|
+
You need to insert images to our index to query on them. The insert function can be written as below.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# id is required field.
|
73
|
+
id = 'image_id'
|
74
|
+
|
75
|
+
# image_url is required field.
|
76
|
+
image_url = "https://example.com/image_url.jpg"
|
77
|
+
|
78
|
+
# Filters argument is optional. You can specify upto 3 filters as per example given below.
|
79
|
+
# Filters can be useful when querying images from our index. You can apply any filter
|
80
|
+
# as per your requirement.
|
81
|
+
filters = ["filter1" => "onefilter", "filter2" => "twofilter", "filter3" => "threefilter"]
|
82
|
+
|
83
|
+
# Metadata is optional. You can pass additional information about your image which will be
|
84
|
+
# returned when you query image from our index.
|
85
|
+
metadata = ["title" => "Image Title"]
|
86
|
+
|
87
|
+
# now let's call the API.
|
88
|
+
resp = @visual.create(id, image_url, filters, metadata)
|
89
|
+
```
|
90
|
+
|
91
|
+
Update
|
92
|
+
------
|
93
|
+
|
94
|
+
If you need to update information to indexed image, you can use update function. If you call update function for id which is not already indexed, it will insert the image to index.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
# id is required field. Provide id for which you need to update the information.
|
98
|
+
id = 'image_id'
|
99
|
+
|
100
|
+
# image_url is optional field. You can pass `null` if you would like to keep URL unchanged.
|
101
|
+
image_url = "https://example.com/image_url.jpg"
|
102
|
+
|
103
|
+
# Filters argument is optional. You can specify upto 3 filters as per example given below.
|
104
|
+
# Filters can be useful when querying images from our index. You can apply any filter
|
105
|
+
# as per your requirement. The filters you provide here will be overwritten.
|
106
|
+
filters = ["filter1" => "onefilter", "filter2" => "twofilter", "filter3" => "threefilter"]
|
107
|
+
|
108
|
+
# Metadata is optional. You can pass additional information about your image which will be
|
109
|
+
# returned when you query image from our index. Existing metadata values will be overwritten
|
110
|
+
# based on keys supplied to this array.
|
111
|
+
metadata = ["title" => "Image Title"]
|
112
|
+
|
113
|
+
# now let's call the API.
|
114
|
+
resp = @visual.update(id, image_url, filters, metadata)
|
115
|
+
```
|
116
|
+
|
117
|
+
Delete
|
118
|
+
------
|
119
|
+
|
120
|
+
You can delete image from index with this method.
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
# id is required field.
|
124
|
+
id = 'image_id'
|
125
|
+
|
126
|
+
# now let's call the API.
|
127
|
+
resp = @visual.delete(id)
|
128
|
+
```
|
129
|
+
|
130
|
+
Visual Search
|
131
|
+
-------------
|
132
|
+
|
133
|
+
Visual search can be used to search indexed images based on query image.
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
# image_url is required field. The API will perform visual search on the image and return
|
137
|
+
image_url = "https://example.com/image_url.jpg"
|
138
|
+
|
139
|
+
# crop_box is optional field. You can supply empty array if you don't want to specify crop box.
|
140
|
+
# The format of crop box is [xmin, ymin, xmax, ymax]
|
141
|
+
crop_box = [188, 256, 656, 928]
|
142
|
+
|
143
|
+
# Filters argument is optional. You can specify upto 3 filters.
|
144
|
+
# For example, if you specify filter1 = "nike", it will only return images which are indexed with
|
145
|
+
# "nike" as filter1.
|
146
|
+
filters = ["filter1" => "nike"]
|
147
|
+
|
148
|
+
# now let's call the API.
|
149
|
+
resp = @visual.search(image_url, crop_box, filters)
|
150
|
+
```
|
151
|
+
|
152
|
+
Visual Recommendations
|
153
|
+
----------------------
|
154
|
+
|
155
|
+
Visual recommendations give visually similar image recommendations which can be used to display recommendation widget on e-commerce sites which greatly improved CTR and conversion rates.
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
# image_url is required field. The API will perform visual search on the image and return
|
159
|
+
id = "some_product_id"
|
160
|
+
|
161
|
+
# Filters argument is optional. You can specify upto 3 filters.
|
162
|
+
# For example, if you specify filter1 = "nike", it will only return images which are indexed with
|
163
|
+
# "nike" as filter1.
|
164
|
+
filters = ["filter1" => "nike"]
|
165
|
+
|
166
|
+
# now let's call the API.
|
167
|
+
resp = @visual.similar(id, filters)
|
168
|
+
```
|
169
|
+
|
170
|
+
Run Tests
|
171
|
+
----------------------
|
172
|
+
|
173
|
+
```sh
|
174
|
+
API_KEY='api_key' rspec
|
175
|
+
```
|
176
|
+
|
177
|
+
## Development
|
178
|
+
|
179
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
180
|
+
|
181
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
182
|
+
|
183
|
+
## Contributing
|
184
|
+
|
185
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/turingiq/turing-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
186
|
+
|
187
|
+
## License
|
188
|
+
|
189
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
190
|
+
|
191
|
+
## Code of Conduct
|
192
|
+
|
193
|
+
Everyone interacting in the TuringAPI project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/turingiq/turing-ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "turing_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/turing_api.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
require "turing_api/version"
|
2
|
+
require 'httparty'
|
3
|
+
require 'byebug'
|
4
|
+
require 'json'
|
5
|
+
require './lib/visual_api_exception'
|
6
|
+
|
7
|
+
module TuringAPI
|
8
|
+
class VisualAPI
|
9
|
+
attr_accessor :api_key, :api_version, :mode, :base_url, :headers
|
10
|
+
|
11
|
+
def similar(id, filters=[])
|
12
|
+
begin
|
13
|
+
request = @mode=="live" ? "similar" : "demo-similar"
|
14
|
+
requested_url = @base_url+"#{request}/#{id}"
|
15
|
+
body = !filters.empty? ? {:filter1=>"#{filters[0]['filter1']}", :filter2=>"#{filters[0]['filter2']}", :filter3=>"#{filters[0]['filter3']}" } : {}
|
16
|
+
response = HTTParty.get(requested_url, headers: @headers, :body => body)
|
17
|
+
response_data = response.body
|
18
|
+
data = JSON.parse(response_data)
|
19
|
+
data
|
20
|
+
rescue JSON::ParserError => e
|
21
|
+
puts "Error message - #{e.message}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def search(url, crop=[], filters=[])
|
26
|
+
begin
|
27
|
+
request = @mode=="live" ? "similar" : "demo-similar"
|
28
|
+
requested_url = @base_url+"#{request}/search"
|
29
|
+
crop_size = !crop.empty? ? crop.join(",") : nil
|
30
|
+
filter1 = !filters.empty? ? filters[0]['filter1'] : ""
|
31
|
+
filter2 = !filters.empty? ? filters[0]['filter2'] : ""
|
32
|
+
filter3 = !filters.empty? ? filters[0]['filter3'] : ""
|
33
|
+
request = HTTParty.post(requested_url, headers: @headers, :body => {:url=>"#{url}", :crop=>"#{crop_size}", :filter1=>"#{filter1}", :filter2=>"#{filter2}", :filter3=>"#{filter3}" })
|
34
|
+
response_data = request.body
|
35
|
+
data = JSON.parse(response_data)
|
36
|
+
data
|
37
|
+
rescue JSON::ParserError => e
|
38
|
+
puts "Error message - #{e.message}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def auto_crop(url)
|
43
|
+
begin
|
44
|
+
requested_url = @base_url+"autocrop"
|
45
|
+
request = HTTParty.get(requested_url, headers: @headers, :body => {:url=>"#{url}"})
|
46
|
+
response_data = request.body
|
47
|
+
data = JSON.parse(response_data)
|
48
|
+
data
|
49
|
+
rescue JSON::ParserError => e
|
50
|
+
puts "Error message - #{e.message}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def create(url, id, filters=[], metadata=[])
|
55
|
+
begin
|
56
|
+
request = @mode=="live" ? "similar" : "demo-similar"
|
57
|
+
requested_url = @base_url+"#{request}/create"
|
58
|
+
filter1 = !filters.empty? ? filters[0]['filter1'] : " "
|
59
|
+
filter2 = !filters.empty? ? filters[0]['filter2'] : " "
|
60
|
+
filter3 = !filters.empty? ? filters[0]['filter3'] : " "
|
61
|
+
title = !metadata.empty? ? metadata[0]['title'] : " "
|
62
|
+
request = HTTParty.post(requested_url, headers: @headers, :body => {:url=>"#{url}", :id=>id, :filter1=>"#{filter1}", :filter2=>"#{filter2}", :filter3=>"#{filter3}", :title=>"#{title}" })
|
63
|
+
response_data = request.body
|
64
|
+
data = JSON.parse(response_data)
|
65
|
+
data
|
66
|
+
rescue JSON::ParserError => e
|
67
|
+
puts "Error message - #{e.message}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def update(url, id, filters=[], metadata=[])
|
72
|
+
begin
|
73
|
+
request = @mode=="live" ? "similar" : "demo-similar"
|
74
|
+
requested_url = @base_url+"#{request}/create"
|
75
|
+
url = url if !url.nil?
|
76
|
+
filter1 = !filters.empty? ? filters[0]['filter1'] : " "
|
77
|
+
filter2 = !filters.empty? ? filters[0]['filter2'] : " "
|
78
|
+
filter3 = !filters.empty? ? filters[0]['filter3'] : " "
|
79
|
+
title = !metadata.empty? ? metadata[0]['title'] : " "
|
80
|
+
request = HTTParty.post(requested_url, headers: @headers, :body => {:url=>"#{url}", :id=>id, :filter1=>"#{filter1}", :filter2=>"#{filter2}", :filter3=>"#{filter3}", :title=>"#{title}" })
|
81
|
+
response_data = request.body
|
82
|
+
data = JSON.parse(response_data)
|
83
|
+
data
|
84
|
+
rescue JSON::ParserError => e
|
85
|
+
puts "Error message - #{e.message}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def delete(id)
|
90
|
+
begin
|
91
|
+
request = @mode=="live" ? "similar" : "demo-similar"
|
92
|
+
requested_url = @base_url+"#{request}/#{id}"
|
93
|
+
response = HTTParty.delete(requested_url, headers: @headers)
|
94
|
+
response_data = response.body
|
95
|
+
data = JSON.parse(response_data)
|
96
|
+
data
|
97
|
+
rescue JSON::ParserError => e
|
98
|
+
puts "Error message - #{e.message}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
private
|
104
|
+
def initialize(api_key, mode="live", api_version="v1")
|
105
|
+
if api_key.nil? || api_key.empty?
|
106
|
+
raise VisualAPIException.new('API key is not provided.')
|
107
|
+
else
|
108
|
+
self.api_key = api_key
|
109
|
+
end
|
110
|
+
|
111
|
+
if api_version != 'v1'
|
112
|
+
raise VisualAPIException.new("Currenly only 'v1' is supported for api version")
|
113
|
+
else
|
114
|
+
self.api_version = api_version
|
115
|
+
end
|
116
|
+
|
117
|
+
if mode != 'live' && mode != 'sandbox'
|
118
|
+
raise VisualAPIException.new("Mode can only be either 'live' or 'sandbox'. You provided: #{mode}")
|
119
|
+
else
|
120
|
+
self.mode = mode
|
121
|
+
end
|
122
|
+
|
123
|
+
self.base_url = "https://api.turingiq.com/#{api_version}/"
|
124
|
+
self.headers = { 'Authorization' => "Bearer #{api_key}" }
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/turing_api.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "turing_api/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "turing_api"
|
8
|
+
spec.version = TuringAPI::VERSION
|
9
|
+
spec.authors = ["Turing Analytics"]
|
10
|
+
spec.email = ["mail@turingiq.com"]
|
11
|
+
|
12
|
+
spec.summary = "A gem for Turing Analytics API."
|
13
|
+
spec.description = "Turing Analytics is driven by a vision to develop solutions powered by machine learning to help businesses make data driven decisions."
|
14
|
+
spec.homepage = "https://api.turingiq.com/doc/"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: turing_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Turing Analytics
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Turing Analytics is driven by a vision to develop solutions powered by
|
56
|
+
machine learning to help businesses make data driven decisions.
|
57
|
+
email:
|
58
|
+
- mail@turingiq.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- lib/turing_api.rb
|
75
|
+
- lib/turing_api/version.rb
|
76
|
+
- lib/visual_api_exception.rb
|
77
|
+
- turing_api.gemspec
|
78
|
+
homepage: https://api.turingiq.com/doc/
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.5.2.3
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: A gem for Turing Analytics API.
|
102
|
+
test_files: []
|