tolq-api 0.2.0 → 0.3.0

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: 258c11a814c532f9b106b0be0006ffcfa938d896
4
- data.tar.gz: 9f12adf9ad861511f37f4d4ae0e55f479c8374df
3
+ metadata.gz: 79808429da5819b754b3ace0836baff58d5ff9a3
4
+ data.tar.gz: 4708a7db5757288b8ccff4ab5d41132aa6da414c
5
5
  SHA512:
6
- metadata.gz: 188798fb0b7a162b740b00910f16a16de378c9923e8e7c78be640c1a0ae21dbb7409c66890a858e41f97e3e98d84759dd73d6f6a716d33c21b05b33a7ca1c111
7
- data.tar.gz: 0205cf15dee5659e58d5757514836a71fd770ae1c8b2831e6becbdbf571a937884bad09ffaf839ba65b5907f2aaa0a26ca9605a21eb8bd718cf376d9a0fd9873
6
+ metadata.gz: b68bfd086a1dacd994a203db2babf9f762057aa103e2f8a4898a41994f9413167794500c370feee08adc95bdc42ce8b5c174d66ad0248004aaeaadf613b18613
7
+ data.tar.gz: 947ec723d387be9512f1c48d65bd20bf2de23cc5e87843636771555e4c8a24fd80faeb115c1c859632f0bcaf831b8f7b37179e959bec01a3b0381234ae0fa5df
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ # 0.3.0
2
+ * Added HMAC signature verification for callbacks
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tolq-api (0.2.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.4.0)
10
+ coderay (1.1.1)
11
+ crack (0.4.3)
12
+ safe_yaml (~> 1.0.0)
13
+ hashdiff (0.3.0)
14
+ method_source (0.8.2)
15
+ minitest (5.9.0)
16
+ pry (0.10.3)
17
+ coderay (~> 1.1.0)
18
+ method_source (~> 0.8.1)
19
+ slop (~> 3.4)
20
+ rake (10.5.0)
21
+ safe_yaml (1.0.4)
22
+ slop (3.6.0)
23
+ webmock (1.24.6)
24
+ addressable (>= 2.3.6)
25
+ crack (>= 0.3.2)
26
+ hashdiff
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ bundler (~> 1.11)
33
+ minitest (~> 5.0)
34
+ pry
35
+ rake (~> 10.0)
36
+ tolq-api!
37
+ webmock (~> 1.24.6)
38
+
39
+ BUNDLED WITH
40
+ 1.11.2
data/README.md CHANGED
@@ -89,12 +89,14 @@ client.translation_request.order(response.id)
89
89
  If you do not have a callback url or are just interested in the status, you can request the status and/or translations as follows:
90
90
 
91
91
  ```ruby
92
- response = client.show_translation_request(<id>)
92
+ response = client.translation_requests.show(<id>)
93
93
  response.class # Tolq::Api::Response
94
94
  response.body # A tolq response as per the documentation. This JSON and can be parsed using your favourite json parser
95
95
  ```
96
+ You can verify a callback HMAC signature by calling `client.valid_signature?`, this can be used to verify the authenticity of a callback.
97
+
98
+ For more details on on the library please refer to the [gem documentation](http://www.rubydoc.info/gems/tolq-api). For more details on possible values see the [api documentation](https://docs.tolq.com).
96
99
 
97
- For more details on on the library please refer to the [gem documentation](TODO). For more details on possible values see the [api documentation](https://docs.tolq.com).
98
100
 
99
101
  ## Development
100
102
 
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ Rake::TestTask.new(:test) do |t|
5
5
  t.libs << 'test'
6
6
  t.libs << 'lib'
7
7
  t.test_files = FileList['test/**/*_test.rb']
8
+ t.warning = false
8
9
  end
9
10
 
10
11
  task default: :test
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pry'
4
+
5
+ require File.expand_path(File.dirname(__FILE__) + '/../lib/tolq-api.rb')
6
+
7
+ pry
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.3.1
@@ -1,4 +1,4 @@
1
- require 'net/http'
1
+ require 'net/https'
2
2
 
3
3
  module Tolq
4
4
  module Api
@@ -23,6 +23,17 @@ module Tolq
23
23
  TranslationRequestApi.new(self)
24
24
  end
25
25
 
26
+ # Verifies a signature on a callback payload
27
+ # You can find the signature in the X-Tolq-Signature
28
+ # header
29
+ #
30
+ # @param signature [String] A sha1 encoded HMAC signature including the 'sha1=' prefix
31
+ # @param payload [String] The body of the payload as a string
32
+ def valid_signature?(signature, payload)
33
+ payload_signature = 'sha1=' + OpenSSL::HMAC.digest('sha1', self.key, payload)
34
+ payload_signature == signature
35
+ end
36
+
26
37
  def get(path, data = nil)
27
38
  response = do_request(:get, path, data)
28
39
  handle_response(response)
@@ -67,7 +78,6 @@ module Tolq
67
78
  end
68
79
 
69
80
  request.body = data.to_json if data
70
- # TODO Probably also need to use tls and verify peer for ssl
71
81
  request.basic_auth @key, @secret
72
82
  request['Content-Type'] = 'application/json'
73
83
 
@@ -2,7 +2,7 @@ module Tolq
2
2
  module Api
3
3
  # Handles all requests dealing with translation requests
4
4
  class TranslationRequestApi
5
- # Creats a new TranslationRequestApi.
5
+ # Creats a new Tolq::Api::ResponseApi.
6
6
  #
7
7
  # Called indirectly via Client#translation_requests
8
8
  #
@@ -15,7 +15,7 @@ module Tolq
15
15
  # Creates and orders a new translation request
16
16
  #
17
17
  # @param request [Hash] A hash consisting of a translation request, this maps 1:1 with the JSON request format. See our documentation for details
18
- # @return [TranslationRequest] A TranslationRequest with an id, status and some metadata
18
+ # @return [Tolq::Api::Response] A Tolq::Api::Response with an id, status and some metadata
19
19
  def create(request)
20
20
  @client.post('/translations/requests', request)
21
21
  end
@@ -23,7 +23,7 @@ module Tolq
23
23
  # Retrieves a translation request
24
24
  #
25
25
  # @param id [Integer] An id referencing a translation request
26
- # @return [TranslationRequest] A TranslationRequest with an id, status and some metadata, if completed the translations are also included
26
+ # @return [Tolq::Api::Response] A Tolq::Api::Response with an id, status and some metadata, if completed the translations are also included
27
27
  def show(id)
28
28
  @client.get("/translations/requests/#{id}")
29
29
  end
@@ -31,14 +31,14 @@ module Tolq
31
31
  # Creates but doesn't order a new translation request
32
32
  #
33
33
  # @param request [Hash] A hash consisting of a translation request, this maps 1:1 with the JSON request format. See our documentation for details
34
- # @return [TranslationRequest] A TranslationRequest with an id, status and some metadata
34
+ # @return [Tolq::Api::Response] A Tolq::Api::Response with an id, status and some metadata
35
35
  def quote(request)
36
36
  @client.post('/translations/requests/quote', request)
37
37
  end
38
38
 
39
39
  # Lists all your translation requests
40
40
  #
41
- # @return [Array<TranslationRequest>] A list of translation requests without translations
41
+ # @return [Tolq::Api::Response] A list of translation requests without translations
42
42
  def list
43
43
  @client.get('/translations/requests')
44
44
  end
@@ -46,7 +46,7 @@ module Tolq
46
46
  # Orders a translation request
47
47
  #
48
48
  # @param id [Integer] An id referencing a translation request
49
- # @return [TranslationRequest] A TranslationRequest with an id, status and some metadata
49
+ # @return [Tolq::Api::Response] A Tolq::Api::Response with an id, status and some metadata
50
50
  def order(id)
51
51
  @client.post("/translations/requests/#{id}/order")
52
52
  end
@@ -1,5 +1,5 @@
1
1
  module Tolq
2
2
  module Api
3
- VERSION = '0.2.0'.freeze
3
+ VERSION = '0.3.0'.freeze
4
4
  end
5
5
  end
data/tolq-api.gemspec CHANGED
@@ -16,12 +16,12 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
18
  spec.bindir = 'bin'
19
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.executables = []
20
20
  spec.require_paths = ['lib']
21
21
 
22
22
  spec.add_development_dependency 'bundler', '~> 1.11'
23
23
  spec.add_development_dependency 'rake', '~> 10.0'
24
24
  spec.add_development_dependency 'minitest', '~> 5.0'
25
25
  spec.add_development_dependency 'pry'
26
- spec.add_development_dependency 'webmock'
26
+ spec.add_development_dependency 'webmock', '~> 1.24.6'
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tolq-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Timon Vonk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-09 00:00:00.000000000 Z
11
+ date: 2016-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.24.6
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 1.24.6
83
83
  description: A gem that wraps the Tolq.com API
84
84
  email:
85
85
  - timon@tolq.com
@@ -89,11 +89,15 @@ extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
91
  - ".travis.yml"
92
+ - CHANGELOG.md
92
93
  - CODE_OF_CONDUCT.md
93
94
  - Gemfile
95
+ - Gemfile.lock
94
96
  - LICENSE.txt
95
97
  - README.md
96
98
  - Rakefile
99
+ - bin/console
100
+ - circle.yml
97
101
  - lib/tolq-api.rb
98
102
  - lib/tolq-api/client.rb
99
103
  - lib/tolq-api/response.rb