rainforest 1.0.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -6
  3. data/.travis.yml +13 -1
  4. data/Gemfile +6 -0
  5. data/README.md +72 -21
  6. data/Rakefile +6 -13
  7. data/VERSION +1 -1
  8. data/bin/rainforest-console +1 -1
  9. data/gemfiles/default-with-activesupport.gemfile +8 -1
  10. data/gemfiles/json.gemfile +10 -2
  11. data/gemfiles/yajl.gemfile +10 -2
  12. data/lib/rainforest.rb +61 -240
  13. data/lib/rainforest/apibits/api_client.rb +28 -0
  14. data/lib/rainforest/apibits/api_endpoint.rb +11 -0
  15. data/lib/rainforest/apibits/api_list.rb +88 -0
  16. data/lib/rainforest/apibits/api_method.rb +95 -0
  17. data/lib/rainforest/apibits/api_object.rb +52 -0
  18. data/lib/rainforest/apibits/api_resource.rb +153 -0
  19. data/lib/rainforest/apibits/headers_builder.rb +47 -0
  20. data/lib/rainforest/apibits/params_builder.rb +27 -0
  21. data/lib/rainforest/apibits/path_builder.rb +38 -0
  22. data/lib/rainforest/apibits/requester.rb +104 -0
  23. data/lib/rainforest/apibits/util.rb +51 -0
  24. data/lib/rainforest/clients/default_client.rb +59 -0
  25. data/lib/rainforest/endpoints/client_stats_endpoint.rb +11 -0
  26. data/lib/rainforest/endpoints/environment_runs_endpoint.rb +11 -0
  27. data/lib/rainforest/endpoints/environments_endpoint.rb +48 -0
  28. data/lib/rainforest/endpoints/generator_rows_endpoint.rb +17 -0
  29. data/lib/rainforest/endpoints/generators_endpoint.rb +48 -0
  30. data/lib/rainforest/endpoints/integrations_endpoint.rb +33 -0
  31. data/lib/rainforest/endpoints/run_tests_endpoint.rb +20 -0
  32. data/lib/rainforest/endpoints/runs_endpoint.rb +48 -0
  33. data/lib/rainforest/endpoints/schedules_endpoint.rb +48 -0
  34. data/lib/rainforest/endpoints/site_environments_endpoint.rb +24 -0
  35. data/lib/rainforest/endpoints/sites_endpoint.rb +39 -0
  36. data/lib/rainforest/endpoints/tests_endpoint.rb +57 -0
  37. data/lib/rainforest/endpoints/users_endpoint.rb +48 -0
  38. data/lib/rainforest/errors/api_connection_error.rb +1 -1
  39. data/lib/rainforest/errors/api_error.rb +32 -1
  40. data/lib/rainforest/errors/authentication_error.rb +1 -1
  41. data/lib/rainforest/errors/rainforest_error.rb +2 -9
  42. data/lib/rainforest/resources/client_stats.rb +31 -0
  43. data/lib/rainforest/resources/environment.rb +73 -0
  44. data/lib/rainforest/resources/generator.rb +73 -0
  45. data/lib/rainforest/resources/integration.rb +52 -0
  46. data/lib/rainforest/resources/run.rb +93 -0
  47. data/lib/rainforest/resources/schedule.rb +63 -0
  48. data/lib/rainforest/resources/site.rb +53 -0
  49. data/lib/rainforest/resources/site_environment.rb +40 -0
  50. data/lib/rainforest/resources/test.rb +98 -0
  51. data/lib/rainforest/resources/user.rb +75 -0
  52. data/rainforest.gemspec +8 -6
  53. data/test/rainforest/api_client_test.rb +51 -0
  54. data/test/rainforest/api_endpoint_test.rb +13 -0
  55. data/test/rainforest/api_list_test.rb +49 -0
  56. data/test/rainforest/api_method_test.rb +78 -0
  57. data/test/rainforest/headers_builder_test.rb +28 -0
  58. data/test/rainforest/params_builder_test.rb +57 -0
  59. data/test/rainforest/path_builder_test.rb +50 -0
  60. data/test/rainforest/requester_test.rb +86 -0
  61. data/test/rainforest/util_test.rb +41 -19
  62. data/test/test_data.rb +72 -0
  63. data/test/test_helper.rb +17 -134
  64. metadata +99 -59
  65. data/CONTRIBUTORS +0 -2
  66. data/History.txt +0 -4
  67. data/LICENSE +0 -21
  68. data/lib/data/ca-certificates.crt +0 -3918
  69. data/lib/rainforest/api_operations/create.rb +0 -16
  70. data/lib/rainforest/api_operations/delete.rb +0 -11
  71. data/lib/rainforest/api_operations/list.rb +0 -16
  72. data/lib/rainforest/api_operations/update.rb +0 -61
  73. data/lib/rainforest/api_resource.rb +0 -33
  74. data/lib/rainforest/errors/invalid_request_error.rb +0 -10
  75. data/lib/rainforest/json.rb +0 -21
  76. data/lib/rainforest/list_object.rb +0 -35
  77. data/lib/rainforest/rainforest_object.rb +0 -165
  78. data/lib/rainforest/run.rb +0 -8
  79. data/lib/rainforest/singleton_api_resource.rb +0 -20
  80. data/lib/rainforest/util.rb +0 -100
  81. data/test/rainforest/api_resource_test.rb +0 -11
  82. data/test/rainforest/auth_test.rb +0 -24
  83. data/test/rainforest/list_object_test.rb +0 -7
  84. data/test/rainforest/metadata_test.rb +0 -7
  85. data/test/rainforest/run_test.rb +0 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a8bd3b90d475c8bc357f753806096ea07ed035c
4
- data.tar.gz: 29c3dff1169f776c2a7dea67fbb8addb0d496979
3
+ metadata.gz: 82b786fc24d65611d96a516701e188e587011fac
4
+ data.tar.gz: 13d9d3e95a6ecc8fa6422f4e75169615bb43de73
5
5
  SHA512:
6
- metadata.gz: 4e313ffb420e372713f6975a0ad12edbb854b3255ead3d4d2291fe7443ea0b022778717ffb722e718fec09dd748cde27af08b21479aaeed80295e74c5c3d4d68
7
- data.tar.gz: 764014897f979f739f9549079e3d2979fbcae4529e7ed6801d3679867f47796e304f5b5918c21b865acf61c950446ecbd6a76e508f45f5b498cd2753a4024078
6
+ metadata.gz: 8cc5b56ef4426f7c9284b6290842715e95efa7a274eb82781055f0209ec95bce8a381db10a7e4286dc97218c9b4010b61364c292bbff4b7b093e009196d9a1bf
7
+ data.tar.gz: 8b01181dbf47463375447865db939c80218a37363c53d024daf25bcde64c410449f6530335e58ef4d6fcbedc0f9b64fd2ed88d11ed1eafab108d78f317204d12
data/.gitignore CHANGED
@@ -1,7 +1,4 @@
1
- /rainforest-*.gem
2
- /Gemfile.lock
3
- .rvmrc
1
+ pkg
4
2
  Gemfile.lock
5
- tags
6
- .DS_Store
7
- *~
3
+ *.gem
4
+ .ruby-version
@@ -1,4 +1,16 @@
1
1
  language: ruby
2
+
2
3
  rvm:
3
- - 2.0.0
4
+ - 1.8.7
5
+ - 1.9.2
4
6
  - 1.9.3
7
+ - 2.0.0
8
+ - 2.1
9
+ - 2.2
10
+
11
+ gemfile:
12
+ - gemfiles/default-with-activesupport.gemfile
13
+ - gemfiles/json.gemfile
14
+ - gemfiles/yajl.gemfile
15
+
16
+ sudo: false
data/Gemfile CHANGED
@@ -1,2 +1,8 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec
3
+
4
+ if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('1.9.3')
5
+ gem 'i18n', '< 0.7'
6
+ gem 'rest-client', '~> 1.6.8'
7
+ gem 'activesupport', '~> 3.2'
8
+ end
data/README.md CHANGED
@@ -1,47 +1,98 @@
1
- [![Build Status](https://travis-ci.org/rainforestapp/rainforest-ruby.png?branch=master)](https://travis-ci.org/rainforestapp/rainforest-ruby)
1
+ # Rainforest Ruby Bindings
2
2
 
3
- # Installation
4
3
 
5
- Install the gem:
6
4
 
7
- ```
5
+ ## Installation
6
+
7
+ You don't need this source code unless you want to modify the gem. If
8
+ you just want to use the Rainforest Ruby bindings, you should run:
9
+
10
+ ```bash
8
11
  gem install rainforest
9
12
  ```
10
13
 
11
- Import the Rainforest client in your application:
14
+ If you want to build & install the gem from source:
15
+
16
+ ```bash
17
+ gem build rainforest.gemspec
18
+ gem install rainforest-2.0.0.gem
19
+ ```
20
+
21
+
22
+ ## Requirements
23
+
24
+ * Ruby 1.8.7 or above. (Ruby 1.8.6 may work if you load
25
+ ActiveSupport.) For Ruby versions before 1.9.2, you'll need to add this to your Gemfile:
12
26
 
13
27
  ```ruby
14
- require 'rainforest'
28
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.2')
29
+ gem 'rest-client', '~> 1.6.8'
30
+ end
15
31
  ```
16
32
 
17
- # Requirements
33
+ * rest-client, json
18
34
 
19
- * Ruby 1.9.3 or above.
20
- * rest-client, multi_json
21
35
 
36
+ ## Bundler
22
37
 
23
- # Examples
38
+ If you are installing via bundler, you should be sure to use the https
39
+ rubygems source in your Gemfile, as any gems fetched over http could potentially be compromised.
24
40
 
25
41
  ```ruby
26
- require 'rainforest'
27
- Rainforest.api_key = "985de0ba7d0820912a33aa696a77319d"
42
+ source 'https://rubygems.org'
43
+
44
+ gem 'rails'
45
+ gem 'rainforest'
46
+ ```
47
+
48
+ ## Using the library
28
49
 
29
- # Get all of your runs
30
- runs = Rainforest::Run.all
50
+ The following section covers some general info about this API library. If you are looking for documentation covering the entire API, check here: [https://docs.rainfroestqa.com](https://docs.rainfroestqa.com).
31
51
 
32
- run = Rainforest::Run.retrieve(2181) # retrieve a run
33
- run.delete # abort a run
52
+ ### Params and Headers
53
+
54
+ All API methods accept 2 optional arguments - the params and headers. For example, if you had `SomeResource` and wanted to call `#some_method(some_arg)`, all of the following would be valid:
55
+
56
+ ```ruby
57
+ # With no custom params or headers
58
+ Rainforest::SomeResource.some_method(some_arg)
34
59
 
60
+ # With only custom params
61
+ Rainforest::SomeResource.some_method(some_arg, params)
35
62
 
36
- # Kick off a run with all tests
37
- new_run = Rainforest::Run.create(tests: ["all"])
63
+ # With only custom headers
64
+ Rainforest::SomeResource.some_method(some_arg, nil, headers)
65
+
66
+ # With both custom params and headers
67
+ Rainforest::SomeResource.some_method(some_arg, params, headers)
38
68
  ```
39
69
 
40
- # Docs
70
+ This is mostly useful when creating new resources, or when trying to use an API endpoint that supports pagination.
71
+
41
72
 
42
- You can find the Rainforest docs here: https://docs.rainforestqa.com/
73
+ ### Using Multiple API Keys
43
74
 
75
+ The API library was designed to support both developers who plan to only use one API key, as well as developers who may need to use multiple API keys in the same server.
44
76
 
45
- # Development
77
+ By default most resource lookups use code like this:
78
+
79
+ ```ruby
80
+ Rainforest.api_key = "your-api-key"
81
+ test = Rainforest::Test.retrieve(id)
82
+ ```
83
+
84
+ but since the API key is set on the module, this could cause issues if you need to use multiple API keys. To get around this, simply use one of the API clients located in the `clients` folder. For example:
85
+
86
+ ```ruby
87
+ client = Rainforest::DefaultClient.new("your-api-key")
88
+ test = client.tests.retreive(id)
89
+ ```
90
+
91
+ The results from each will be the same, so if you prefer the client version you are welcome to use it even if you aren't using multiple API keys in production.
92
+
93
+
94
+ ## Development
46
95
 
47
96
  Test cases can be run with: `bundle exec rake test`
97
+
98
+ We welcome suggestions and feedback from our users :D
data/Rakefile CHANGED
@@ -1,15 +1,8 @@
1
- task :default => [:all]
1
+ require 'rake/testtask'
2
+ require 'yaml'
2
3
 
3
- task :test do
4
- ret = true
5
- Dir["test/**/*_test.rb"].each do |f|
6
- ret = ret && ruby(f, '')
7
- end
8
- end
4
+ task :default => [:test]
9
5
 
10
- task :all do
11
- Rake::Task["test"].invoke
12
- require 'active_support/all'
13
- Rake::Task["test"].reenable
14
- Rake::Task["test"].invoke
15
- end
6
+ Rake::TestTask.new do |t|
7
+ t.pattern = './test/**/[^_]*_test.rb'
8
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.7
1
+ 2.0.0
@@ -3,5 +3,5 @@ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
3
3
 
4
4
  libs = " -r irb/completion"
5
5
  libs << " -r #{File.dirname(__FILE__) + '/../lib/rainforest'}"
6
- puts "Loading rainforest gem"
6
+ puts "Loading Rainforest gem"
7
7
  exec "#{irb} #{libs} --simple-prompt"
@@ -1,3 +1,10 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec :path => File.join(File.dirname(__FILE__), "..")
3
- gem "activesupport", "~> 3.0"
3
+
4
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.3')
5
+ gem 'i18n', '< 0.7'
6
+ gem 'rest-client', '~> 1.6.8'
7
+ gem 'activesupport', '~> 3.2'
8
+ else
9
+ gem 'activesupport'
10
+ end
@@ -1,4 +1,12 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec :path => File.join(File.dirname(__FILE__), "..")
3
- gem "json"
4
- gem "activesupport", "~> 3.0"
3
+
4
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.3')
5
+ gem 'i18n', '< 0.7'
6
+ gem 'rest-client', '~> 1.6.8'
7
+ gem 'activesupport', '~> 3.2'
8
+ else
9
+ gem 'activesupport'
10
+ end
11
+
12
+ gem 'json'
@@ -1,4 +1,12 @@
1
1
  source "https://rubygems.org"
2
2
  gemspec :path => File.join(File.dirname(__FILE__), "..")
3
- gem "yajl-ruby"
4
- gem "activesupport", "~> 3.0"
3
+
4
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.3')
5
+ gem 'i18n', '< 0.7'
6
+ gem 'rest-client', '~> 1.6.8'
7
+ gem 'activesupport', '~> 3.2'
8
+ else
9
+ gem 'activesupport'
10
+ end
11
+
12
+ gem 'yajl-ruby'
@@ -1,262 +1,83 @@
1
1
  # Rainforest Ruby bindings
2
- # API spec at https://rainforest.com/docs/api
2
+ # API Docs are located at https://docs.rainfroestqa.com
3
3
  require 'cgi'
4
4
  require 'set'
5
5
  require 'openssl'
6
6
  require 'rest_client'
7
- require 'multi_json'
7
+ require 'json'
8
+ require 'base64'
8
9
 
9
10
  # Version
10
11
  require 'rainforest/version'
11
12
 
12
- # API operations
13
- require 'rainforest/api_operations/create'
14
- require 'rainforest/api_operations/update'
15
- require 'rainforest/api_operations/delete'
16
- require 'rainforest/api_operations/list'
17
-
18
- # Resources
19
- require 'rainforest/util'
20
- require 'rainforest/json'
21
- require 'rainforest/rainforest_object'
22
- require 'rainforest/api_resource'
23
- require 'rainforest/singleton_api_resource'
24
- require 'rainforest/list_object'
25
- require 'rainforest/run'
26
-
27
13
  # Errors
28
14
  require 'rainforest/errors/rainforest_error'
29
15
  require 'rainforest/errors/api_error'
30
16
  require 'rainforest/errors/api_connection_error'
31
- require 'rainforest/errors/invalid_request_error'
32
17
  require 'rainforest/errors/authentication_error'
33
18
 
34
- module Rainforest
35
- @api_base = 'https://app.rainforestqa.com/api'
36
- @api_version = 1
37
-
38
- # TODO(jon): Verify that this will work with rainforest
39
- @ssl_bundle_path = File.dirname(__FILE__) + '/data/ca-certificates.crt'
40
- @verify_ssl_certs = true
41
-
42
- class << self
43
- attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version
44
- end
45
-
46
- def self.api_url(url='')
47
- @api_base + "/" + @api_version.to_s + url
48
- end
49
-
50
- def self.request(method, url, api_key, params={}, headers={})
51
- unless api_key ||= @api_key
52
- raise AuthenticationError.new('No API key provided. ' +
53
- 'Set your API key using "Rainforest.api_key = <API-KEY>". ' +
54
- 'You can generate API keys from the Rainforest web interface. ' +
55
- 'See https://rainforest.com/api for details, or email support@rainforest.com ' +
56
- 'if you have any questions.')
57
- end
58
-
59
- if api_key =~ /\s/
60
- raise AuthenticationError.new('Your API key is invalid, as it contains ' +
61
- 'whitespace. (HINT: You can double-check your API key from the ' +
62
- 'Rainforest web interface. See https://rainforest.com/api for details, or ' +
63
- 'email support@rainforest.com if you have any questions.)')
64
- end
65
-
66
- request_opts = { :verify_ssl => false }
67
-
68
- if ssl_preflight_passed?
69
- request_opts.update(:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
70
- :ssl_ca_file => @ssl_bundle_path)
71
- end
72
-
73
- params = Util.objects_to_ids(params)
74
- url = api_url(url)
75
-
76
- case method.to_s.downcase.to_sym
77
- when :get, :head, :delete
78
- # Make params into GET parameters
79
- url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any?
80
- payload = nil
81
- else
82
- payload = uri_encode(params)
83
- end
84
-
85
- request_opts.update(:headers => request_headers(api_key).update(headers),
86
- :method => method, :open_timeout => 30,
87
- :payload => payload, :url => url, :timeout => 80)
88
-
89
- begin
90
- response = execute_request(request_opts)
91
- rescue SocketError => e
92
- handle_restclient_error(e)
93
- rescue NoMethodError => e
94
- # Work around RestClient bug
95
- if e.message =~ /\WRequestFailed\W/
96
- e = APIConnectionError.new('Unexpected HTTP response code')
97
- handle_restclient_error(e)
98
- else
99
- raise
100
- end
101
- rescue RestClient::ExceptionWithResponse => e
102
- if rcode = e.http_code and rbody = e.http_body
103
- handle_api_error(rcode, rbody)
104
- else
105
- handle_restclient_error(e)
106
- end
107
- rescue RestClient::Exception, Errno::ECONNREFUSED => e
108
- handle_restclient_error(e)
109
- end
110
-
111
- [parse(response), api_key]
112
- end
113
-
114
- private
115
-
116
- def self.ssl_preflight_passed?
117
- if !verify_ssl_certs && !@no_verify
118
- $stderr.puts "WARNING: Running without SSL cert verification. " +
119
- "Execute 'Rainforest.verify_ssl_certs = true' to enable verification."
120
-
121
- @no_verify = true
122
-
123
- elsif !Util.file_readable(@ssl_bundle_path) && !@no_bundle
124
- $stderr.puts "WARNING: Running without SSL cert verification " +
125
- "because #{@ssl_bundle_path} isn't readable"
126
-
127
- @no_bundle = true
128
- end
129
-
130
- !(@no_verify || @no_bundle)
131
- end
132
-
133
- def self.user_agent
134
- @uname ||= get_uname
135
- lang_version = "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})"
136
-
137
- {
138
- :bindings_version => Rainforest::VERSION,
139
- :lang => 'ruby',
140
- :lang_version => lang_version,
141
- :platform => RUBY_PLATFORM,
142
- :publisher => 'rainforest',
143
- :uname => @uname
144
- }
145
-
146
- end
147
-
148
- def self.get_uname
149
- `uname -a 2>/dev/null`.strip if RUBY_PLATFORM =~ /linux|darwin/i
150
- rescue Errno::ENOMEM => ex # couldn't create subprocess
151
- "uname lookup failed"
152
- end
153
-
154
- def self.uri_encode(params)
155
- Util.flatten_params(params).
156
- map { |k,v| "#{k}=#{Util.url_encode(v)}" }.join('&')
157
- end
158
-
159
- def self.request_headers(api_key)
160
- headers = {
161
- :user_agent => "Rainforest/#{api_version} RubyBindings/#{Rainforest::VERSION}",
162
-
163
- # TODO(jon): Ask Rainforest guys about using http basic auth
164
- # :authorization => "Bearer #{api_key}",
165
- "Accept" => "application/json",
166
- "CLIENT_TOKEN" => api_key,
167
- :content_type => 'application/x-www-form-urlencoded'
168
- }
169
-
170
- headers[:rainforest_version] = api_version if api_version
171
-
172
- begin
173
- headers.update(:x_rainforest_client_user_agent => Rainforest::JSON.dump(user_agent))
174
- rescue => e
175
- headers.update(:x_rainforest_client_raw_user_agent => user_agent.inspect,
176
- :error => "#{e} (#{e.class})")
177
- end
178
- end
179
-
180
- def self.execute_request(opts)
181
- RestClient::Request.execute(opts)
182
- end
183
-
184
- def self.parse(response)
185
- begin
186
- # Would use :symbolize_names => true, but apparently there is
187
- # some library out there that makes symbolize_names not work.
188
- response = Rainforest::JSON.load(response.body)
189
- rescue MultiJson::DecodeError
190
- raise general_api_error(response.code, response.body)
191
- end
192
-
193
- Util.symbolize_names(response)
194
- end
195
-
196
- def self.general_api_error(rcode, rbody)
197
- APIError.new("Invalid response object from API: #{rbody.inspect} " +
198
- "(HTTP response code was #{rcode})", rcode, rbody)
199
- end
200
-
201
- def self.handle_api_error(rcode, rbody)
202
- begin
203
- error_obj = Rainforest::JSON.load(rbody)
204
- error_obj = Util.symbolize_names(error_obj)
205
- error = error_obj[:error] or raise RainforestError.new # escape from parsing
206
-
207
- rescue MultiJson::DecodeError, RainforestError
208
- raise general_api_error(rcode, rbody)
209
- end
210
-
211
- case rcode
212
- when 400, 404
213
- raise invalid_request_error error, rcode, rbody, error_obj
214
- when 401
215
- raise authentication_error error, rcode, rbody, error_obj
216
- else
217
- raise api_error error, rcode, rbody, error_obj
218
- end
19
+ # Wrapper around RestClient
20
+ require 'rainforest/apibits/requester'
21
+
22
+ # Builders for creating API methods.
23
+ require 'rainforest/apibits/path_builder'
24
+ require 'rainforest/apibits/headers_builder'
25
+ require 'rainforest/apibits/params_builder'
26
+ require 'rainforest/apibits/api_method'
27
+
28
+ # Generic resources
29
+ require 'rainforest/apibits/api_endpoint'
30
+ require 'rainforest/apibits/api_client'
31
+ require 'rainforest/apibits/api_object'
32
+ require 'rainforest/apibits/api_resource'
33
+ require 'rainforest/apibits/api_list'
34
+ require 'rainforest/apibits/util'
35
+
36
+ # API specific resources
37
+ require 'rainforest/resources/client_stats'
38
+ require 'rainforest/resources/environment'
39
+ require 'rainforest/resources/generator'
40
+ require 'rainforest/resources/integration'
41
+ require 'rainforest/resources/run'
42
+ require 'rainforest/resources/schedule'
43
+ require 'rainforest/resources/site_environment'
44
+ require 'rainforest/resources/site'
45
+ require 'rainforest/resources/test'
46
+ require 'rainforest/resources/user'
47
+
48
+ # API specific endpoints
49
+ require 'rainforest/endpoints/client_stats_endpoint'
50
+ require 'rainforest/endpoints/environment_runs_endpoint'
51
+ require 'rainforest/endpoints/environments_endpoint'
52
+ require 'rainforest/endpoints/generators_endpoint'
53
+ require 'rainforest/endpoints/generator_rows_endpoint'
54
+ require 'rainforest/endpoints/integrations_endpoint'
55
+ require 'rainforest/endpoints/run_tests_endpoint'
56
+ require 'rainforest/endpoints/runs_endpoint'
57
+ require 'rainforest/endpoints/schedules_endpoint'
58
+ require 'rainforest/endpoints/site_environments_endpoint'
59
+ require 'rainforest/endpoints/sites_endpoint'
60
+ require 'rainforest/endpoints/tests_endpoint'
61
+ require 'rainforest/endpoints/users_endpoint'
62
+
63
+ # API specific clients
64
+ require 'rainforest/clients/default_client'
219
65
 
220
- end
221
-
222
- def self.invalid_request_error(error, rcode, rbody, error_obj)
223
- InvalidRequestError.new("Invalid Request Error", error[:param], rcode,
224
- rbody, error_obj)
225
- end
226
66
 
227
- def self.authentication_error(error, rcode, rbody, error_obj)
228
- AuthenticationError.new("Authentication Error", rcode, rbody, error_obj)
229
- end
67
+ module Rainforest
68
+ @api_base = "https://app.rainforestqa.com/api/1"
69
+ @api_staging = "https://app.rnfrst.com/api/1/"
70
+ @api_version = "v1"
71
+ @support_email = "help@rainforestqa.com"
72
+ @docs_url = "https://docs.rainfroestqa.com"
230
73
 
231
- def self.api_error(error, rcode, rbody, error_obj)
232
- APIError.new(error[:message], rcode, rbody, error_obj)
74
+ class << self
75
+ attr_accessor :api_base, :api_version
76
+ attr_reader :api_staging, :support_email, :docs_url
77
+ attr_accessor :api_key
233
78
  end
234
79
 
235
- def self.handle_restclient_error(e)
236
- case e
237
- when RestClient::ServerBrokeConnection, RestClient::RequestTimeout
238
- message = "Could not connect to Rainforest (#{@api_base}). " +
239
- "Please check your internet connection and try again. " +
240
- "If this problem persists, you should check Rainforest's service status at " +
241
- "https://twitter.com/rainforeststatus, or let us know at support@rainforest.com."
242
-
243
- when RestClient::SSLCertificateNotVerified
244
- message = "Could not verify Rainforest's SSL certificate. " +
245
- "Please make sure that your network is not intercepting certificates. " +
246
- "(Try going to https://api.rainforest.com/v1 in your browser.) " +
247
- "If this problem persists, let us know at support@rainforest.com."
248
-
249
- when SocketError
250
- message = "Unexpected error communicating when trying to connect to Rainforest. " +
251
- "You may be seeing this message because your DNS is not working. " +
252
- "To check, try running 'host rainforest.com' from the command line."
253
-
254
- else
255
- message = "Unexpected error communicating with Rainforest. " +
256
- "If this problem persists, let us know at support@rainforest.com."
257
-
258
- end
259
-
260
- raise APIConnectionError.new(message + "\n\n(Network error: #{e.message})")
80
+ def self.default_client
81
+ DefaultClient.new(Rainforest.api_key)
261
82
  end
262
83
  end