turbot-api 0.0.16 → 0.0.17

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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- N2Y4YTk5MDAwZGE4MDQxNjE1NzI2NDVhMWVjY2UxZDRmYTdkNTc3MA==
5
- data.tar.gz: !binary |-
6
- NjVhNGUxNDJiZTJkZWY3Y2RlNGMzYjY0YTQzMmIzMTliNTk0OWUyNw==
2
+ SHA1:
3
+ metadata.gz: f67fab8e48984f6105b1ba156021609ae79097bb
4
+ data.tar.gz: 75013c5a69f091e9340b09c10a3144bb20607c5a
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- Yjk1NjkwM2ZmNTQxODA0MjkzNWU0ZWU0NTg3ZGY4ZDZlNmRmYzdlNzE0NDFj
10
- YjUzZDQ2NzgwYWU0YzQ3ZGEyMDEzYmRiM2ViMzNjNGYzNjk3OWVjMDVhNmJh
11
- YThiM2Y1MzJjYTI2ODEwYjFkMzYwNDVjNWQ2NGM5MDc3ZDE2YTk=
12
- data.tar.gz: !binary |-
13
- MGQxYjI0MGZkNDBlYmFlYTZlODdiYTJkOTdlYTdiNDgyOWRhZGQwMTEwMTk2
14
- MmUwZDJmZGExZGE5NGIxMjhlNjVjZDQ3MDg3N2U0NTljM2Q4M2Q4NDRmNTE4
15
- NmY5YWU3MWNiMWY2MDM5MzZiYmMzN2M5YjZmYzBmMzVjZjY3Nzg=
6
+ metadata.gz: 7f439061492bb9ebc9d61577fc220a8b1b2c609304442054bba56b2db2768f3a30697a2f1c70d8c28942b4b5bc336384bd7ffa8ebbeb5b4e038a1a86ea9b5e77
7
+ data.tar.gz: b753d3240fc152cf4cb1fa2bd26a2e1f4cbdae3c99c20d1b4cef71abc76b7ca149119cbdf5b359c5a42e227a1242be637112663196ce3aab696e0a92058bc5d5
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ .yardoc
4
+ coverage
5
+ Gemfile.lock
6
+ doc/*
7
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --order random
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - 2.2.0
9
+ - 2.3.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in the gemspec
4
+ gemspec
data/README.md CHANGED
@@ -0,0 +1,14 @@
1
+ # turbot-api
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/turbot-api.svg)](https://badge.fury.io/rb/turbot-api)
4
+ [![Build Status](https://secure.travis-ci.org/openc/turbot-api.png)](https://travis-ci.org/openc/turbot-api)
5
+ [![Dependency Status](https://gemnasium.com/openc/turbot-api.png)](https://gemnasium.com/openc/turbot-api)
6
+ [![Coverage Status](https://coveralls.io/repos/openc/turbot-api/badge.png)](https://coveralls.io/r/openc/turbot-api)
7
+ [![Code Climate](https://codeclimate.com/github/openc/turbot-api.png)](https://codeclimate.com/github/openc/turbot-api)
8
+
9
+ ## Releasing a new version
10
+
11
+ Bump the version in `lib/turbot/api/version.rb` according to the [Semantic Versioning](http://semver.org/) convention, then:
12
+
13
+ git commit lib/turbot/api/version.rb -m 'Release new version'
14
+ rake release # requires Rubygems credentials
@@ -0,0 +1,16 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+
9
+ begin
10
+ require 'yard'
11
+ YARD::Rake::YardocTask.new
12
+ rescue LoadError
13
+ task :yard do
14
+ abort 'YARD is not available. In order to run yard, you must: gem install yard'
15
+ end
16
+ end
@@ -0,0 +1,123 @@
1
+ require 'cgi'
2
+ require 'json'
3
+
4
+ require 'rest_client'
5
+
6
+ require 'turbot/api/response'
7
+
8
+ module Turbot
9
+ class API
10
+ def initialize(params)
11
+ @host = params[:host]
12
+ @port = params[:port]
13
+ @scheme = params[:scheme]
14
+ @api_key = params[:api_key] || get_api_key_for_credentials(params[:username], params[:password])['api_key']
15
+ end
16
+
17
+ # @return [Hash] a hash with the user's details
18
+ def get_user
19
+ response = request(:get, '/api/user')
20
+
21
+ # For backwards compatibility, this method must return a Hash, not a SuccessResponse.
22
+ JSON.load(response.body)
23
+ end
24
+
25
+ # @return [String] the user's API key
26
+ def get_api_key
27
+ get_user['api_key']
28
+ end
29
+
30
+ # @return [Hash] a hash with a single key "api_key"
31
+ def get_api_key_for_credentials(user, password)
32
+ response = request(:get, '/api/user/api_key', {
33
+ :email => user,
34
+ :password => password,
35
+ })
36
+
37
+ # For backwards compatibility, this method must return a Hash, not a SuccessResponse.
38
+ JSON.load(response.body)
39
+ end
40
+
41
+ # @return [Turbot::API::SuccessResponse, Turbot::API::FailureResponse]
42
+ def list_bots
43
+ request(:get, '/api/bots')
44
+ end
45
+
46
+ # @return [Turbot::API::SuccessResponse, Turbot::API::FailureResponse]
47
+ def show_bot(bot_id)
48
+ request(:get, "/api/bots/#{bot_id}")
49
+ end
50
+
51
+ # @return [Turbot::API::SuccessResponse, Turbot::API::FailureResponse]
52
+ def create_bot(bot_id, config, env = nil)
53
+ request(:post, '/api/bots', :bot => {:bot_id => bot_id, :config => config, :env => env})
54
+ end
55
+
56
+ # @return [Turbot::API::SuccessResponse, Turbot::API::FailureResponse]
57
+ def update_bot(bot_id, config, env = nil)
58
+ request(:put, "/api/bots/#{bot_id}", :bot => {:config => config, :env => env})
59
+ end
60
+
61
+ # @return [Turbot::API::SuccessResponse, Turbot::API::FailureResponse]
62
+ def show_manifest(bot_id)
63
+ request(:get, "/api/bots/#{bot_id}/manifest")
64
+ end
65
+
66
+ # @return [Turbot::API::SuccessResponse, Turbot::API::FailureResponse]
67
+ def create_draft_data(bot_id, batch)
68
+ request(:post, "/api/bots/#{bot_id}/draft_data", :batch => batch)
69
+ end
70
+
71
+ # @return [Turbot::API::SuccessResponse, Turbot::API::FailureResponse]
72
+ def destroy_draft_data(bot_id)
73
+ request(:delete, "/api/bots/#{bot_id}/draft_data")
74
+ end
75
+
76
+ # @return [Turbot::API::SuccessResponse, Turbot::API::FailureResponse]
77
+ def update_code(bot_id, archive)
78
+ request(:put, "/api/bots/#{bot_id}/code", {:archive => archive}, false)
79
+ end
80
+
81
+ # @return [Turbot::API::SuccessResponse, Turbot::API::FailureResponse]
82
+ def start_run(bot_id)
83
+ request(:post, "/api/bots/#{bot_id}/run/start")
84
+ end
85
+
86
+ # @return [Turbot::API::SuccessResponse, Turbot::API::FailureResponse]
87
+ def stop_run(bot_id)
88
+ request(:post, "/api/bots/#{bot_id}/run/stop")
89
+ end
90
+
91
+ private
92
+
93
+ def build_url_and_params(path, params = {})
94
+ url = URI::HTTP.build({
95
+ :host => @host,
96
+ :port => @port,
97
+ :scheme => @scheme,
98
+ :path => path.strip,
99
+ }).to_s
100
+
101
+ params[:api_key] = @api_key
102
+
103
+ [url, params]
104
+ end
105
+
106
+ def request(method, path, params = {}, json = true)
107
+ url, params = build_url_and_params(path, params)
108
+
109
+ begin
110
+ if method == :get || method == :delete
111
+ response = RestClient.send(method, url, :params => params)
112
+ elsif json == false
113
+ response = RestClient.send(method, url, params)
114
+ else
115
+ response = RestClient.send(method, url, JSON.dump(params), :content_type => :json)
116
+ end
117
+ SuccessResponse.new(response)
118
+ rescue RestClient::Exception => e
119
+ FailureResponse.new(e.response)
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,31 @@
1
+ module Turbot
2
+ class API
3
+ class Response < SimpleDelegator
4
+ attr_reader :message
5
+
6
+ def initialize(response)
7
+ super
8
+ @parsed_body = JSON.parse(response.body, :symbolize_names => true)
9
+ @message = @parsed_body[:message]
10
+ end
11
+ end
12
+
13
+ class SuccessResponse < Response
14
+ attr_reader :data
15
+
16
+ def initialize(response)
17
+ super
18
+ @data = @parsed_body[:data]
19
+ end
20
+ end
21
+
22
+ class FailureResponse < Response
23
+ attr_reader :error_code
24
+
25
+ def initialize(response)
26
+ super
27
+ @error_code = @parsed_body[:error_code]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Turbot
2
+ class API
3
+ VERSION = '0.0.17'
4
+ end
5
+ end
@@ -1,2 +1,2 @@
1
- require 'turbot_api/api'
2
- require 'turbot_api/errors'
1
+ # `require 'turbot_api'` is deprecated. Use `require 'turbot/api'`.
2
+ require 'turbot/api'
@@ -1,25 +1,83 @@
1
- require 'turbot_api'
1
+ require 'spec_helper'
2
2
 
3
- describe Turbot::API do
4
- before do
5
- @api = Turbot::API.new(:api_key => 'key', :host => 'example.com')
3
+ RSpec.describe Turbot::API do
4
+ let :api do
5
+ Turbot::API.new(:host => 'example.com', :api_key => 'key')
6
+ end
7
+
8
+ let :api_without_key do
9
+ Turbot::API.new(:host => 'example.com', :api_key => '')
10
+ end
11
+
12
+ describe '#get_user' do
13
+ it 'succeeds' do
14
+ body = {
15
+ 'email' => 'email@example.com',
16
+ 'last_sign_in_at' => '2015-01-01T00:00:00.000Z',
17
+ 'api_key' => 'key',
18
+ 'bot_count' => 5,
19
+ }
20
+
21
+ expect(RestClient).to receive(:get).
22
+ with('http://example.com/api/user', :params => {:api_key => 'key'}).
23
+ and_return(double(:body => JSON.dump(body)))
24
+
25
+ result = api.get_user
26
+ expect(result).to be_a(Hash)
27
+ expect(result).to eq(body)
28
+ end
29
+ end
30
+
31
+ describe '#get_api_key_for_credentials' do
32
+ it 'succeeds' do
33
+ body = {
34
+ 'api_key' => 'key'
35
+ }
36
+
37
+ expect(RestClient).to receive(:get).
38
+ with('http://example.com/api/user/api_key', :params => {:email => 'email@example.com', :password => 'pass', :api_key => ''}).
39
+ and_return(double(:body => JSON.dump(body)))
40
+
41
+ result = api_without_key.get_api_key_for_credentials('email@example.com', 'pass')
42
+ expect(result).to be_a(Hash)
43
+ expect(result).to eq(body)
44
+ end
45
+ end
46
+
47
+ describe '#update_code' do
48
+ it 'succeeds' do
49
+ data = {}
50
+ body = JSON.dump({
51
+ :data => data,
52
+ })
53
+
54
+ expect(RestClient).to receive(:put).
55
+ with('http://example.com/api/bots/example/code', :api_key => 'key', :archive => 'binary').
56
+ and_return(double(:body => body))
57
+
58
+ result = api.update_code('example', 'binary')
59
+ expect(result).to be_a(Turbot::API::SuccessResponse)
60
+ expect(result.body).to eq(body)
61
+ expect(result.message).to eq(nil)
62
+ expect(result.data).to eq(data)
63
+ end
6
64
  end
7
65
 
8
66
  describe '#start_run' do
9
67
  it 'starts a run' do
10
- RestClient.should_receive(:post).
11
- with('http://example.com/api/bots/test-bot/run/start', :api_key => 'key').
12
- and_return(double(:body => {}.to_json))
13
- @api.start_run('test-bot')
68
+ expect(RestClient).to receive(:post).
69
+ with('http://example.com/api/bots/test-bot/run/start', JSON.dump(:api_key => 'key') , :content_type => :json).
70
+ and_return(double(:body => JSON.dump({})))
71
+ api.start_run('test-bot')
14
72
  end
15
73
  end
16
74
 
17
75
  describe '#stop_run' do
18
76
  it 'stops a run' do
19
- RestClient.should_receive(:post).
20
- with('http://example.com/api/bots/test-bot/run/stop', :api_key => 'key').
21
- and_return(double(:body => {}.to_json))
22
- @api.stop_run('test-bot')
77
+ expect(RestClient).to receive(:post).
78
+ with('http://example.com/api/bots/test-bot/run/stop', JSON.dump(:api_key => 'key'), :content_type => :json).
79
+ and_return(double(:body => JSON.dump({})))
80
+ api.stop_run('test-bot')
23
81
  end
24
82
  end
25
83
  end
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+
3
+ require 'simplecov'
4
+ require 'coveralls'
5
+ SimpleCov.formatter = Coveralls::SimpleCov::Formatter
6
+ SimpleCov.start do
7
+ add_filter 'spec'
8
+ end
9
+
10
+ require 'rspec'
11
+ require File.dirname(__FILE__) + '/../lib/turbot/api'
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../lib/turbot/api/version', __FILE__)
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = "turbot-api"
5
+ gem.version = Turbot::API::VERSION
6
+
7
+ gem.author = "OpenCorporates"
8
+ gem.email = "bots@opencorporates.com"
9
+ gem.homepage = "https://github.com/openc/turbot-api"
10
+ gem.summary = "Turbot API client"
11
+ gem.license = "MIT"
12
+
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.require_paths = ["lib"]
17
+
18
+ gem.add_runtime_dependency('rest-client', '~> 1.8')
19
+
20
+ gem.add_development_dependency('coveralls')
21
+ gem.add_development_dependency('rake')
22
+ gem.add_development_dependency('rspec', '~> 3.4')
23
+ end
metadata CHANGED
@@ -1,56 +1,91 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbot-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
- - Turbot
7
+ - OpenCorporates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-10 00:00:00.000000000 Z
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.6.1
19
+ version: '1.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.6.1
26
+ version: '1.8'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rubyzip
28
+ name: coveralls
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :runtime
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ! '>='
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
- description: Client library to deploy apps on Turbot.
42
- email: support@opencorporates.com
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ description:
70
+ email: bots@opencorporates.com
43
71
  executables: []
44
72
  extensions: []
45
73
  extra_rdoc_files: []
46
74
  files:
75
+ - ".gitignore"
76
+ - ".rspec"
77
+ - ".travis.yml"
78
+ - Gemfile
47
79
  - README.md
80
+ - Rakefile
81
+ - lib/turbot/api.rb
82
+ - lib/turbot/api/response.rb
83
+ - lib/turbot/api/version.rb
48
84
  - lib/turbot_api.rb
49
- - lib/turbot_api/api.rb
50
- - lib/turbot_api/errors.rb
51
- - lib/turbot_api/version.rb
52
85
  - spec/api_spec.rb
53
- homepage: http://opencorporates.com/
86
+ - spec/spec_helper.rb
87
+ - turbot-api.gemspec
88
+ homepage: https://github.com/openc/turbot-api
54
89
  licenses:
55
90
  - MIT
56
91
  metadata: {}
@@ -60,19 +95,21 @@ require_paths:
60
95
  - lib
61
96
  required_ruby_version: !ruby/object:Gem::Requirement
62
97
  requirements:
63
- - - ! '>='
98
+ - - ">="
64
99
  - !ruby/object:Gem::Version
65
100
  version: '0'
66
101
  required_rubygems_version: !ruby/object:Gem::Requirement
67
102
  requirements:
68
- - - ! '>='
103
+ - - ">="
69
104
  - !ruby/object:Gem::Version
70
105
  version: '0'
71
106
  requirements: []
72
107
  rubyforge_project:
73
- rubygems_version: 2.2.2
108
+ rubygems_version: 2.4.5
74
109
  signing_key:
75
110
  specification_version: 4
76
- summary: Client library to deploy apps on Turbot.
77
- test_files: []
111
+ summary: Turbot API client
112
+ test_files:
113
+ - spec/api_spec.rb
114
+ - spec/spec_helper.rb
78
115
  has_rdoc:
@@ -1,152 +0,0 @@
1
- require 'json'
2
- require 'rest_client'
3
- require 'cgi'
4
-
5
- module Turbot
6
- class API
7
- def initialize(params)
8
- @headers = params[:headers]
9
- @host = params[:host]
10
- @port = params[:port]
11
- @username = params[:username]
12
- @password = params[:password]
13
- @scheme = params[:scheme]
14
- @ssl_verify_peer = params[:ssl_verify_peer]
15
- @api_key = params[:api_key] || get_api_key_for_credentials(@username, @password)["api_key"]
16
- end
17
-
18
- def get_user
19
- # TODO move away from using RestClient directly
20
- response = RestClient.get(server_req("/api/user"))
21
- JSON.parse(response)
22
- end
23
-
24
- def get_api_key
25
- get_user["api_key"]
26
- end
27
-
28
- def get_api_key_for_credentials(user, password)
29
- # TODO move away from using RestClient directly
30
- url = server_req("/api/user/api_key",
31
- :email => user,
32
- :password => password)
33
- response = RestClient.get(url)
34
- JSON.parse(response)
35
- end
36
-
37
- def list_bots
38
- request(:get, "/api/bots")
39
- end
40
-
41
- def show_bot(bot_id)
42
- request(:get, "/api/bots/#{bot_id}")
43
- end
44
-
45
- def create_bot(bot_id, config)
46
- request(:post, "/api/bots", :bot => {:bot_id => bot_id, :config => config})
47
- end
48
-
49
- def update_bot(bot_id, config)
50
- request(:put, "/api/bots/#{bot_id}", :bot => {:config => config})
51
- end
52
-
53
- def show_manifest(bot_id)
54
- request(:get, "/api/bots/#{bot_id}/manifest")
55
- end
56
-
57
- def create_draft_data(bot_id, batch)
58
- request(:post, "/api/bots/#{bot_id}/draft_data", :batch => batch)
59
- end
60
-
61
- def destroy_draft_data(bot_id)
62
- request(:delete, "/api/bots/#{bot_id}/draft_data")
63
- end
64
-
65
- def update_code(bot_id, archive)
66
- # We can't use #request here since we're not sending JSON
67
- url = build_url("/api/bots/#{bot_id}/code")
68
- begin
69
- response = RestClient.put(url, :api_key => @api_key, :archive => archive)
70
- SuccessResponse.new(response)
71
- rescue RestClient::Exception => e
72
- FailureResponse.new(e.response)
73
- end
74
- end
75
-
76
- def start_run(bot_id)
77
- request(:post, "/api/bots/#{bot_id}/run/start")
78
- end
79
-
80
- def stop_run(bot_id)
81
- request(:post, "/api/bots/#{bot_id}/run/stop")
82
- end
83
-
84
- def get_ssh_keys
85
- []
86
- end
87
-
88
- def post_key(key)
89
- end
90
-
91
- private
92
-
93
- def server_req(path, params={})
94
- query_string = params.update(:api_key => @api_key).map do |k, v|
95
- "#{k}=#{CGI::escape(v)}" if v
96
- end.compact.join("&")
97
- args = {
98
- :host => @host,
99
- :port => @port,
100
- :scheme => @scheme,
101
- :path => path.strip
102
- }
103
- args[:query] = query_string unless query_string.empty?
104
- URI::HTTP.build(args).to_s
105
- end
106
-
107
- def request(method, path, params={})
108
- url = build_url(path)
109
-
110
- begin
111
- if method == :get || method == :delete
112
- response = RestClient.send(method, url, :params => params.merge(:api_key => @api_key))
113
- else
114
- response = RestClient.send(method, url, params.merge(:api_key => @api_key).to_json, :content_type => :json)
115
- end
116
- SuccessResponse.new(response)
117
- rescue RestClient::Exception => e
118
- FailureResponse.new(e.response)
119
- end
120
- end
121
-
122
- def build_url(path)
123
- args = {
124
- :host => @host,
125
- :port => @port,
126
- :scheme => @scheme,
127
- :path => path.strip
128
- }
129
- url = URI::HTTP.build(args).to_s
130
- end
131
-
132
- class SuccessResponse
133
- attr_reader :message, :data
134
-
135
- def initialize(response)
136
- data = JSON.parse(response.body, :symbolize_names => true)
137
- @message = data[:message]
138
- @data = data[:data]
139
- end
140
- end
141
-
142
- class FailureResponse
143
- attr_reader :message, :data
144
-
145
- def initialize(response)
146
- data = JSON.parse(response.body, :symbolize_names => true)
147
- @error_code = data[:error_code]
148
- @message = data[:message]
149
- end
150
- end
151
- end
152
- end
@@ -1,28 +0,0 @@
1
- module Turbot
2
- class API
3
- module Errors
4
- class Error < StandardError; end
5
-
6
- class ErrorWithResponse < Error
7
- attr_reader :response
8
-
9
- def initialize(message, response=nil)
10
- message = message << "\nbody: #{response.body.inspect}" if response
11
- super message
12
- @response = response
13
- end
14
- end
15
-
16
- class Unauthorized < ErrorWithResponse; end
17
- class VerificationRequired < ErrorWithResponse; end
18
- class Forbidden < ErrorWithResponse; end
19
- class NotFound < ErrorWithResponse; end
20
- class Timeout < ErrorWithResponse; end
21
- class Locked < ErrorWithResponse; end
22
- class RateLimitExceeded < ErrorWithResponse; end
23
- class RequestFailed < ErrorWithResponse; end
24
- class NilApp < ErrorWithResponse; end
25
- class MissingManifest < ErrorWithResponse; end
26
- end
27
- end
28
- end
@@ -1,3 +0,0 @@
1
- module Turbot
2
- TURBOT_API_VERSION = "0.0.16"
3
- end