sorry-api-ruby 0.0.1
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 +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +85 -0
- data/Rakefile +1 -0
- data/lib/sorry/api.rb +16 -0
- data/lib/sorry/api/client.rb +74 -0
- data/lib/sorry/api/endpoint.rb +7 -0
- data/lib/sorry/api/request.rb +82 -0
- data/lib/sorry/api/version.rb +5 -0
- data/sorry-api-ruby.gemspec +29 -0
- data/spec/sorry/api/client_spec.rb +82 -0
- data/spec/sorry/api/request_spec.rb +51 -0
- data/spec/spec_helper.rb +47 -0
- metadata +163 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 42f99a51702d04ea9c92deb01ff4bb76b8cdb2bb
|
|
4
|
+
data.tar.gz: 04c59b4eb2b861a1e3d327780578af19a4452c43
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 173446fa96a09a9f6a6e67d3b4b351ed4cc4521c81ef4ec30008b50c371a7e915fa2245567118847ab36a8bd3996cf8964f0981c4f03a05fcaebe96f1417cfb7
|
|
7
|
+
data.tar.gz: a3727778b9850426eeecccb897a8295b1bcdb3dcaa7dbe9a151c1ef58b00be2bd464fb82f3b33ec410662902060a10384092806fbf8275bb49e16dc0981d6d9a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2016 SORRYAPP LTD
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Sorry™ API - Ruby
|
|
2
|
+
|
|
3
|
+
> An easy to use Ruby wrapper for the [Sorry™](http://www.sorryapp.com) Status Page API. For details on what you can do with the API please check our [API Documentation](https://docs.sorryapp.com/api/v1/).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To install the gem into the application you need to add it to your Gemfile.
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem "sorry-api-ruby"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Once this has been done you can run `bundle install` to install the gem into your bundle.
|
|
14
|
+
|
|
15
|
+
## Configuration
|
|
16
|
+
|
|
17
|
+
Once the gem is installed you're ready to get up and running with it.
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
client = Sorry::Api::Client.new('put your access token in here')
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
You can also instantiate the client without an access token, and it'll look for an ENV variable called 'SORRY_ACCESS_TOKEN' which is the preferable more-secure option if you're only ever connecting to a single Sorry™ account.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
Now you have your client you can begin to make requests to the API. This is done my chaining methods to match the path defined in the [Documentation](https://docs.sorryapp.com/api/v1/), and then terminate the call by the method you wish to perform i.e. *get(), create(), update() or delete().*
|
|
28
|
+
|
|
29
|
+
##### GET
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
client.pages.get # => Lists all the pages in the account.
|
|
33
|
+
client.pages('kjh324jh').get # => Returns a single page with the given ID.
|
|
34
|
+
client.pages('kjh324jh').brand.get # => Returns the pages brand settings.
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
##### POST/PUT
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
client.pages.create(:name => 'My New Status Page') # => Creates a new page.
|
|
41
|
+
client.pages('kjh324jh').update(:name => 'My Pages New Name') # => Updates the name of the page.
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
##### DELETE
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
client.pages('kjh324jh').delete # => Deletes the page with the given ID.
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Contributing
|
|
51
|
+
|
|
52
|
+
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
|
|
53
|
+
|
|
54
|
+
Once you are happy that your contribution is ready for production please send us a pull request, at which point we'll review the code and merge it in.
|
|
55
|
+
|
|
56
|
+
## Versioning
|
|
57
|
+
|
|
58
|
+
For transparency and insight into our release cycle, and for striving to maintain backward compatibility, This project will be maintained under the Semantic Versioning guidelines as much as possible.
|
|
59
|
+
|
|
60
|
+
Releases will be numbered with the following format:
|
|
61
|
+
|
|
62
|
+
`<major>.<minor>.<patch>`
|
|
63
|
+
|
|
64
|
+
And constructed with the following guidelines:
|
|
65
|
+
|
|
66
|
+
* Breaking backward compatibility bumps the major (and resets the minor and patch)
|
|
67
|
+
* New additions without breaking backward compatibility bumps the minor (and resets the patch)
|
|
68
|
+
* Bug fixes and misc changes bumps the patch
|
|
69
|
+
|
|
70
|
+
For more information on SemVer, please visit <http://semver.org/>.
|
|
71
|
+
|
|
72
|
+
## Authors & Contributors
|
|
73
|
+
|
|
74
|
+
**Robert Rawlins**
|
|
75
|
+
|
|
76
|
+
+ <http://twitter.com/sirrawlins>
|
|
77
|
+
+ <https://github.com/SirRawlins>
|
|
78
|
+
|
|
79
|
+
**Robin Geall**
|
|
80
|
+
|
|
81
|
+
+ <http://twitter.com/robingeall>
|
|
82
|
+
|
|
83
|
+
## Copyright
|
|
84
|
+
|
|
85
|
+
© Copyright 2016 - See [LICENSE](LICENSE) for details.
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/sorry/api.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Import external 3rd party gems.
|
|
2
|
+
# TODO: Add included 3rd party gems here.
|
|
3
|
+
require "faraday"
|
|
4
|
+
require "multi_json"
|
|
5
|
+
|
|
6
|
+
# Import classes and modules for this gem.
|
|
7
|
+
require "sorry/api/version"
|
|
8
|
+
require "sorry/api/endpoint"
|
|
9
|
+
require "sorry/api/client"
|
|
10
|
+
require "sorry/api/request"
|
|
11
|
+
|
|
12
|
+
# Define the core module.
|
|
13
|
+
module Sorry
|
|
14
|
+
module Api
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Sorry
|
|
2
|
+
module Api
|
|
3
|
+
# The core API Client class, instantiated using
|
|
4
|
+
# the access token from your account. All requests stem from
|
|
5
|
+
# here.
|
|
6
|
+
class Client
|
|
7
|
+
|
|
8
|
+
# Attributes.
|
|
9
|
+
attr_accessor :access_token
|
|
10
|
+
|
|
11
|
+
# Initialize the API client.
|
|
12
|
+
def initialize(access_token: nil)
|
|
13
|
+
# Define the API Key, fallback to class config and/or environment variables.
|
|
14
|
+
@access_token = access_token || ENV['SORRY_ACCESS_TOKEN']
|
|
15
|
+
|
|
16
|
+
# TODO: Validate that it was able to intialize with an API key.
|
|
17
|
+
|
|
18
|
+
# Create an empty array to store the path
|
|
19
|
+
# parts for the recursive request building.
|
|
20
|
+
@path_parts = []
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Define the CRUD based methods.
|
|
24
|
+
%w(get post put delete).each do |name|
|
|
25
|
+
# Define the method based on it's name.
|
|
26
|
+
define_method "#{name}" do |**args|
|
|
27
|
+
# Nest in begin block for ensure to work.
|
|
28
|
+
begin
|
|
29
|
+
# Make the request to the API.
|
|
30
|
+
Sorry::Api::Request.new(builder: self).send("#{name}", **args)
|
|
31
|
+
ensure
|
|
32
|
+
# Reset the path once the request has
|
|
33
|
+
# been completed ready to have a new one
|
|
34
|
+
# placed together.
|
|
35
|
+
reset_path
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Path compilation.
|
|
41
|
+
#
|
|
42
|
+
# We use a method chaining on the missing method to build
|
|
43
|
+
# path. so pages().notices().updates() compiles to a string path
|
|
44
|
+
# of /pages/notice/updates which is then used to request the
|
|
45
|
+
# data back from the API.
|
|
46
|
+
|
|
47
|
+
# Get the entire path.
|
|
48
|
+
def path
|
|
49
|
+
# Combine the parts into a single string.
|
|
50
|
+
@path_parts.join('/')
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Use the missing methods to build
|
|
54
|
+
# the path using the method name as the
|
|
55
|
+
# part in the request path.
|
|
56
|
+
def method_missing(method, *args)
|
|
57
|
+
# To support underscores, we replace them with hyphens when calling the API
|
|
58
|
+
@path_parts << method.to_s.gsub("_", "-").downcase
|
|
59
|
+
# Append any arguments to the path.
|
|
60
|
+
@path_parts << args if args.length > 0
|
|
61
|
+
# Flatter the parts to remove any duplcuates.
|
|
62
|
+
@path_parts.flatten!
|
|
63
|
+
# Return an instance of self
|
|
64
|
+
# so we can chain methods together.
|
|
65
|
+
self
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Reset the path parts once a CRUD
|
|
69
|
+
# method has been called.
|
|
70
|
+
def reset_path; @path_parts = []; end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
module Sorry
|
|
2
|
+
module Api
|
|
3
|
+
# The core requests library, I actually build and
|
|
4
|
+
# make the HTTP requests to the API, parse responses etc.
|
|
5
|
+
class Request
|
|
6
|
+
|
|
7
|
+
# Initialze the request class.
|
|
8
|
+
def initialize(builder)
|
|
9
|
+
# Include the build class which
|
|
10
|
+
# will give us access to the path.
|
|
11
|
+
# TODO: Should we instantiate with this? or make this class methods?
|
|
12
|
+
@request_builder = builder
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Define the CRUD based methods.
|
|
16
|
+
%w(get post put delete).each do |name|
|
|
17
|
+
# Define the method based on it's name.
|
|
18
|
+
define_method "#{name}" do |**args|
|
|
19
|
+
# Try making the request.
|
|
20
|
+
begin
|
|
21
|
+
# Make the request through the REST client.
|
|
22
|
+
response = http_client.send("#{name}") do |request|
|
|
23
|
+
# Build the request with the parameters.
|
|
24
|
+
configure_request(request: request, params: args)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Pasrse the response from the request.
|
|
28
|
+
parse_response(response.body)
|
|
29
|
+
# Handle any errors which occurr.
|
|
30
|
+
rescue => e
|
|
31
|
+
# Pass the request off to the error handler.
|
|
32
|
+
handle_error(e)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Build the request from the
|
|
38
|
+
# givden parameters.
|
|
39
|
+
def configure_request(request: nil, params: nil)
|
|
40
|
+
# Set the URL of the request from the compiled path.
|
|
41
|
+
request.url @request_builder.path
|
|
42
|
+
# Marge the parameters into the request.
|
|
43
|
+
request.params.merge!(params) if params
|
|
44
|
+
# Set the request type to JSON.
|
|
45
|
+
request.headers['Content-Type'] = 'application/json'
|
|
46
|
+
# Include the bearer header if one applied as token.
|
|
47
|
+
request.headers['Content-Type']
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Handle/Parse an errors which happen.
|
|
51
|
+
def handle_error(error)
|
|
52
|
+
# Reraise the error for now.
|
|
53
|
+
# TODO: Handler proper errors somehow.
|
|
54
|
+
raise error
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Parse the reponse.
|
|
58
|
+
def parse_response(response_body)
|
|
59
|
+
# Parse the response body from JSON into Hash.
|
|
60
|
+
# Return the enveloped 'response' element.
|
|
61
|
+
MultiJson.load(response_body, :symbolize_keys => true)[:response]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Get access to the HTTP client to make the request.
|
|
65
|
+
def http_client
|
|
66
|
+
# Configure Faraday as our HTTP client.
|
|
67
|
+
Faraday.new(Sorry::Api::ENDPOINT) do |faraday|
|
|
68
|
+
# Configure the adapter to throw erros
|
|
69
|
+
# based on the HTTP response codes.
|
|
70
|
+
faraday.response :raise_error
|
|
71
|
+
# Log to the command ling.
|
|
72
|
+
faraday.response :logger
|
|
73
|
+
# make requests with Net::HTTP
|
|
74
|
+
faraday.adapter Faraday.default_adapter
|
|
75
|
+
# Set the HTTP oAuth headers.
|
|
76
|
+
faraday.authorization :bearer, @request_builder.access_token if @request_builder.access_token
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'sorry/api/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "sorry-api-ruby"
|
|
8
|
+
spec.version = Sorry::Api::VERSION
|
|
9
|
+
spec.authors = ["Robert Rawlins"]
|
|
10
|
+
spec.email = ["robert@sorryapp.com"]
|
|
11
|
+
spec.summary = "A Ruby gem for communicating with the Sorry™ API "
|
|
12
|
+
spec.description = "An easy to use Ruby wrapper for the Sorry™ Status Page API. For details on what you can do with the API please check our API Documentation."
|
|
13
|
+
spec.homepage = "https://docs.sorryapp.com/api/v1/"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_dependency 'faraday', '>= 0.9.1'
|
|
22
|
+
spec.add_dependency 'multi_json', '>= 1.11.0'
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
|
25
|
+
spec.add_development_dependency "rake"
|
|
26
|
+
spec.add_development_dependency "rspec", "3.2.0"
|
|
27
|
+
spec.add_development_dependency 'webmock', "~> 1.21.0"
|
|
28
|
+
spec.add_development_dependency 'faker'
|
|
29
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Sorry::Api::Client do
|
|
4
|
+
|
|
5
|
+
# Placeholder access token.
|
|
6
|
+
let(:access_token) { Faker::Internet.password(128) }
|
|
7
|
+
|
|
8
|
+
describe 'attributes' do
|
|
9
|
+
|
|
10
|
+
it 'has no access token by default' do
|
|
11
|
+
# Instantiate the class.
|
|
12
|
+
client = Sorry::Api::Client.new
|
|
13
|
+
# Expect the client to have no access token.
|
|
14
|
+
expect(client.access_token).to be_nil
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'sets the access token on instantiation' do
|
|
18
|
+
# Instantiate the class.
|
|
19
|
+
client = Sorry::Api::Client.new(access_token: access_token)
|
|
20
|
+
# Expect the client to have no access token.
|
|
21
|
+
expect(client.access_token).to eq(access_token)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'sets an API key from the SORRY_ACCESS_TOKEN ENV variable' do
|
|
25
|
+
# Set the placeholder ENV variable.
|
|
26
|
+
ENV['SORRY_ACCESS_TOKEN'] = access_token
|
|
27
|
+
# Instantiate the class.
|
|
28
|
+
client = Sorry::Api::Client.new
|
|
29
|
+
# Check that the correct token was set.
|
|
30
|
+
expect(client.access_token).to eq(access_token)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it 'sets the API key from the setter' do
|
|
34
|
+
# Instantiate the class.
|
|
35
|
+
client = Sorry::Api::Client.new
|
|
36
|
+
# Set the access token manually.
|
|
37
|
+
client.access_token = access_token
|
|
38
|
+
# Assert that the token is corrcetly set.
|
|
39
|
+
expect(client.access_token).to eq(access_token)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe 'building the path' do
|
|
45
|
+
|
|
46
|
+
# Provide a skeleton client.
|
|
47
|
+
let(:client) { Sorry::Api::Client.new }
|
|
48
|
+
let(:method) { Faker::Lorem.word }
|
|
49
|
+
|
|
50
|
+
# Mock the path parts into the class.
|
|
51
|
+
before(:each) { client.instance_variable_set(:@path_parts, ['mock', 'path', 'parts']) }
|
|
52
|
+
|
|
53
|
+
it 'can reset the path' do
|
|
54
|
+
# Reset the path parts.
|
|
55
|
+
client.reset_path
|
|
56
|
+
# Expect the path parts to be empty array.
|
|
57
|
+
expect(client.instance_variable_get(:@path_parts)).to be_empty
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it 'can generate a url styled path' do
|
|
61
|
+
# Expect a nice slash delimited path.
|
|
62
|
+
expect(client.path).to eq('mock/path/parts')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'adds missing methods to the path' do
|
|
66
|
+
# Empty the path parts before testing.
|
|
67
|
+
client.instance_variable_set(:@path_parts, [])
|
|
68
|
+
# Make a request with a radnom method name.
|
|
69
|
+
client.send(method)
|
|
70
|
+
# Check to see if the path parts now contains
|
|
71
|
+
# the name of the method we invoked.
|
|
72
|
+
expect(client.instance_variable_get(:@path_parts)).to include(method)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'returns an instance of itself for chaining' do
|
|
76
|
+
# Make a request with a radnom method name.
|
|
77
|
+
client.send(method).to be(client)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Sorry::Api::Request do
|
|
4
|
+
|
|
5
|
+
# Placeholder access token.
|
|
6
|
+
let(:access_token) { Faker::Internet.password(128) }
|
|
7
|
+
|
|
8
|
+
# Mock the request object.
|
|
9
|
+
let(:request) { Sorry::Api::Request.new(Sorry::Api::Client.new(access_token: access_token)) }
|
|
10
|
+
|
|
11
|
+
describe 'error handling' do
|
|
12
|
+
|
|
13
|
+
it 'should reraise any errors' do
|
|
14
|
+
# Pass the error handler a new instance of error.
|
|
15
|
+
expect{request.handle_error(StandardError.new)}.to raise_exception(StandardError)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe 'response parsing' do
|
|
21
|
+
|
|
22
|
+
# Mock the response body to test the parses.
|
|
23
|
+
let(:response_body) { '{"response":{"id": 1, "name": "Some name"}}' }
|
|
24
|
+
|
|
25
|
+
it 'should return an response outside of its envelope' do
|
|
26
|
+
# Expect the parses to remove the envelop.
|
|
27
|
+
expect(request.parse_response(response_body)).to eq({:id => 1, :name => "Some name"})
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe 'the HTTP client' do
|
|
33
|
+
|
|
34
|
+
it 'should be a Faraday client' do
|
|
35
|
+
# Ask the instance for the http_client
|
|
36
|
+
expect(request.http_client).to be_a(Faraday::Connection)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it 'should be configured with the URL for the endpoint' do
|
|
40
|
+
# Ask the instance for the http_client
|
|
41
|
+
expect(request.http_client.url_prefix.to_s).to eq(Sorry::Api::ENDPOINT)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it 'has the access_token as a bearer header' do
|
|
45
|
+
# Ask the instance for the http_client
|
|
46
|
+
expect(request.http_client.headers).to include({"Authorization"=>"bearer #{access_token}"})
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Require the libs for testing.
|
|
2
|
+
require 'sorry/api'
|
|
3
|
+
# Faker lib for placeholder data.
|
|
4
|
+
require 'faker'
|
|
5
|
+
|
|
6
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
7
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
8
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
|
9
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
|
10
|
+
# files.
|
|
11
|
+
#
|
|
12
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
|
13
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
|
14
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
|
15
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
|
16
|
+
# a separate helper file that requires the additional dependencies and performs
|
|
17
|
+
# the additional setup, and require it from the spec files that actually need
|
|
18
|
+
# it.
|
|
19
|
+
#
|
|
20
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
|
21
|
+
# users commonly want.
|
|
22
|
+
#
|
|
23
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
24
|
+
RSpec.configure do |config|
|
|
25
|
+
# rspec-expectations config goes here. You can use an alternate
|
|
26
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
27
|
+
# assertions if you prefer.
|
|
28
|
+
config.expect_with :rspec do |expectations|
|
|
29
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
30
|
+
# and `failure_message` of custom matchers include text for helper methods
|
|
31
|
+
# defined using `chain`, e.g.:
|
|
32
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
|
33
|
+
# # => "be bigger than 2 and smaller than 4"
|
|
34
|
+
# ...rather than:
|
|
35
|
+
# # => "be bigger than 2"
|
|
36
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
|
40
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
41
|
+
config.mock_with :rspec do |mocks|
|
|
42
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
|
43
|
+
# a real object. This is generally recommended, and will default to
|
|
44
|
+
# `true` in RSpec 4.
|
|
45
|
+
mocks.verify_partial_doubles = true
|
|
46
|
+
end
|
|
47
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sorry-api-ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Robert Rawlins
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-02-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: faraday
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.9.1
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.9.1
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: multi_json
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 1.11.0
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 1.11.0
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: bundler
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.5'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1.5'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rake
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rspec
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - '='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: 3.2.0
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - '='
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: 3.2.0
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: webmock
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 1.21.0
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 1.21.0
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: faker
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
description: An easy to use Ruby wrapper for the Sorry™ Status Page API. For details
|
|
112
|
+
on what you can do with the API please check our API Documentation.
|
|
113
|
+
email:
|
|
114
|
+
- robert@sorryapp.com
|
|
115
|
+
executables: []
|
|
116
|
+
extensions: []
|
|
117
|
+
extra_rdoc_files: []
|
|
118
|
+
files:
|
|
119
|
+
- ".gitignore"
|
|
120
|
+
- ".rspec"
|
|
121
|
+
- Gemfile
|
|
122
|
+
- LICENSE
|
|
123
|
+
- README.md
|
|
124
|
+
- Rakefile
|
|
125
|
+
- lib/sorry/.DS_Store
|
|
126
|
+
- lib/sorry/api.rb
|
|
127
|
+
- lib/sorry/api/.DS_Store
|
|
128
|
+
- lib/sorry/api/client.rb
|
|
129
|
+
- lib/sorry/api/endpoint.rb
|
|
130
|
+
- lib/sorry/api/request.rb
|
|
131
|
+
- lib/sorry/api/version.rb
|
|
132
|
+
- sorry-api-ruby.gemspec
|
|
133
|
+
- spec/sorry/api/client_spec.rb
|
|
134
|
+
- spec/sorry/api/request_spec.rb
|
|
135
|
+
- spec/spec_helper.rb
|
|
136
|
+
homepage: https://docs.sorryapp.com/api/v1/
|
|
137
|
+
licenses:
|
|
138
|
+
- MIT
|
|
139
|
+
metadata: {}
|
|
140
|
+
post_install_message:
|
|
141
|
+
rdoc_options: []
|
|
142
|
+
require_paths:
|
|
143
|
+
- lib
|
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
|
+
requirements:
|
|
146
|
+
- - ">="
|
|
147
|
+
- !ruby/object:Gem::Version
|
|
148
|
+
version: '0'
|
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
|
+
requirements:
|
|
151
|
+
- - ">="
|
|
152
|
+
- !ruby/object:Gem::Version
|
|
153
|
+
version: '0'
|
|
154
|
+
requirements: []
|
|
155
|
+
rubyforge_project:
|
|
156
|
+
rubygems_version: 2.2.2
|
|
157
|
+
signing_key:
|
|
158
|
+
specification_version: 4
|
|
159
|
+
summary: A Ruby gem for communicating with the Sorry™ API
|
|
160
|
+
test_files:
|
|
161
|
+
- spec/sorry/api/client_spec.rb
|
|
162
|
+
- spec/sorry/api/request_spec.rb
|
|
163
|
+
- spec/spec_helper.rb
|