sendle-api 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 +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +4 -0
- data/lib/sendle/api.rb +15 -0
- data/lib/sendle/api/actions/index.rb +25 -0
- data/lib/sendle/api/errors/missing_api_key.rb +9 -0
- data/lib/sendle/api/errors/missing_sendle_id.rb +9 -0
- data/lib/sendle/api/errors/unauthorized.rb +9 -0
- data/lib/sendle/api/ping.rb +11 -0
- data/lib/sendle/api/responses/pong.rb +9 -0
- data/lib/sendle/api/version.rb +5 -0
- data/lib/sendle/utils/actions.rb +19 -0
- data/sendle-api.gemspec +29 -0
- data/spec/sendle/api/ping_spec.rb +45 -0
- data/spec/sendle/api_spec.rb +20 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/helpers.rb +7 -0
- data/spec/support/shared_examples/with_credentials_spec.rb +39 -0
- data/tasks/rspec.rake +5 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e8ccaab4d83714d1b4ca21fa6c187fa8bce1513
|
4
|
+
data.tar.gz: f8df1382bd0eb6578e1c8c3dc0673d9b024ff647
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f940dc5aac60f8dbe72dd19caa5919c88f27167702b43f072310064fbe45e69f32b3478d027eb71cade3d55a7183b2e642ee38aa439b62df72d45912be76c973
|
7
|
+
data.tar.gz: e243834ebc730d86c9a6d775e8249c52df7a07e08cfec50b0ce58a5940e64375d2c7452ab463c236b616ec7e36734d9193a960802e5d429c116c9be1054921b9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 mebobby2
|
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,44 @@
|
|
1
|
+
# Sendle::Api
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'sendle-api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install sendle-api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/sendle-api/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
32
|
+
|
33
|
+
## Notes
|
34
|
+
### Development
|
35
|
+
1. Navigate to root of this project
|
36
|
+
2. Run bundle install to install the gems specified in sendle-api.gemspec
|
37
|
+
3. Run bundle exec rake spec to run the tests
|
38
|
+
|
39
|
+
### Release
|
40
|
+
1. Make sure you have a RubyGems.org account
|
41
|
+
2. bundle exec rake release
|
42
|
+
|
43
|
+
### Guide
|
44
|
+
Based on this guide: https://quickleft.com/blog/engineering-lunch-series-step-by-step-guide-to-building-your-first-ruby-gem
|
data/Rakefile
ADDED
data/lib/sendle/api.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
module Sendle
|
4
|
+
module Api
|
5
|
+
module Actions
|
6
|
+
module Index
|
7
|
+
|
8
|
+
def index
|
9
|
+
Sendle::Api::Utils::Actions.check_for_missing_credentials
|
10
|
+
RestClient::Request.execute(
|
11
|
+
method: :get,
|
12
|
+
url: self.url,
|
13
|
+
user: Sendle::Api.sendle_id,
|
14
|
+
password: Sendle::Api.api_key,
|
15
|
+
headers: Sendle::Api::Utils::Actions.json_headers
|
16
|
+
)
|
17
|
+
Sendle::Api::Responses::Pong.new
|
18
|
+
rescue RestClient::Unauthorized => e
|
19
|
+
response = JSON.parse(e.response)
|
20
|
+
raise Sendle::Api::Errors::Unauthorized.new(response['error_description'])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sendle
|
2
|
+
module Api
|
3
|
+
module Utils
|
4
|
+
class Actions
|
5
|
+
|
6
|
+
def self.check_for_missing_credentials
|
7
|
+
raise Sendle::Api::Errors::MissingSendleId if Sendle::Api.sendle_id.nil?
|
8
|
+
raise Sendle::Api::Errors::MissingApiKey if Sendle::Api.api_key.nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.json_headers
|
12
|
+
{ accept: :json, content_type: :json }
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/sendle-api.gemspec
ADDED
@@ -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 'sendle/api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sendle-api"
|
8
|
+
spec.version = Sendle::Api::VERSION
|
9
|
+
spec.authors = ["Bobby Lei"]
|
10
|
+
spec.email = ["bobl53@gmail.com"]
|
11
|
+
spec.summary = "Ruby bindings for the Sendle API"
|
12
|
+
spec.description = "Sendle allows businesses to send parcels door to door for low flat-rates Australia wide. See https://www.sendle.com for details."
|
13
|
+
spec.homepage = "http://api-doc.sendle.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "require_all"
|
26
|
+
spec.add_development_dependency "byebug"
|
27
|
+
|
28
|
+
spec.add_dependency('rest-client')
|
29
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Sendle::Api::Ping do
|
4
|
+
|
5
|
+
let(:api_key) { 'fake-key' }
|
6
|
+
let(:sendle_id) { 'fake-id' }
|
7
|
+
|
8
|
+
before do
|
9
|
+
Sendle::Api.api_key = api_key
|
10
|
+
Sendle::Api.sendle_id = sendle_id
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#execute" do
|
14
|
+
it_behaves_like "a resource action with credentials"
|
15
|
+
|
16
|
+
it "makes the correct request" do
|
17
|
+
expected_params = json_headers.merge(
|
18
|
+
method: :get,
|
19
|
+
url: Sendle::Api::Ping.url,
|
20
|
+
user: sendle_id,
|
21
|
+
password: api_key
|
22
|
+
)
|
23
|
+
expect(RestClient::Request).to receive(:execute).with(hash_including(expected_params))
|
24
|
+
|
25
|
+
Sendle::Api::Ping.execute
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns a pong" do
|
29
|
+
expect(RestClient::Request).to receive(:execute)
|
30
|
+
|
31
|
+
pong = Sendle::Api::Ping.execute
|
32
|
+
|
33
|
+
expect(pong).to be_a Sendle::Api::Responses::Pong
|
34
|
+
end
|
35
|
+
|
36
|
+
it "handles unauthorized" do
|
37
|
+
expect(RestClient::Request).to receive(:execute).and_raise(UNAUTHORIZED_ERROR)
|
38
|
+
|
39
|
+
expect {
|
40
|
+
Sendle::Api::Ping.execute
|
41
|
+
}.to raise_error(Sendle::Api::Errors::Unauthorized)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Sendle::Api do
|
4
|
+
|
5
|
+
it "allows setting of the api_key" do
|
6
|
+
api_key = "testing-api-key"
|
7
|
+
|
8
|
+
Sendle::Api.api_key = api_key
|
9
|
+
|
10
|
+
expect(Sendle::Api.api_key).to eq api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
it "allows setting the sendle_id" do
|
14
|
+
sendle_id = "testing-sendle-id"
|
15
|
+
|
16
|
+
Sendle::Api.sendle_id = sendle_id
|
17
|
+
|
18
|
+
expect(Sendle::Api.sendle_id).to eq sendle_id
|
19
|
+
end
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
|
3
|
+
def json_headers
|
4
|
+
{ headers: { accept: :json, content_type: :json } }
|
5
|
+
end
|
6
|
+
|
7
|
+
UNAUTHORIZED_ERROR = RestClient::Unauthorized.new("{\"error\":\"unauthorised\",\"error_description\":\"The authorisation details are not valid. Either the Sendle ID or API key are incorrect.\"}")
|
@@ -0,0 +1,39 @@
|
|
1
|
+
shared_examples_for "a resource action with credentials" do
|
2
|
+
|
3
|
+
describe "setting of credentials" do
|
4
|
+
described_resource = example.metadata[:described_class]
|
5
|
+
described_action = example.metadata[:example_group][:parent_example_group][:parent_example_group][:description_args].first.gsub("#", "")
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(RestClient::Request).to receive(:execute)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "throws an missing sendle_id error" do
|
12
|
+
Sendle::Api.sendle_id = nil
|
13
|
+
Sendle::Api.api_key = 'fake-key'
|
14
|
+
|
15
|
+
expect {
|
16
|
+
described_resource.send(described_action)
|
17
|
+
}.to raise_error Sendle::Api::Errors::MissingSendleId
|
18
|
+
end
|
19
|
+
|
20
|
+
it "throws an missing api_key error" do
|
21
|
+
Sendle::Api.sendle_id = 'fake-id'
|
22
|
+
Sendle::Api.api_key = nil
|
23
|
+
|
24
|
+
expect {
|
25
|
+
described_resource.send(described_action)
|
26
|
+
}.to raise_error Sendle::Api::Errors::MissingApiKey
|
27
|
+
end
|
28
|
+
|
29
|
+
it "does not throw errors if both api_key and sendle_id are set" do
|
30
|
+
Sendle::Api.sendle_id = 'sdfsfdsf'
|
31
|
+
Sendle::Api.api_key = 'sdfsfdsf'
|
32
|
+
|
33
|
+
expect {
|
34
|
+
described_resource.send(described_action)
|
35
|
+
}.to_not raise_error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sendle-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bobby Lei
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-28 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: require_all
|
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: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rest-client
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Sendle allows businesses to send parcels door to door for low flat-rates
|
98
|
+
Australia wide. See https://www.sendle.com for details.
|
99
|
+
email:
|
100
|
+
- bobl53@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/sendle/api.rb
|
111
|
+
- lib/sendle/api/actions/index.rb
|
112
|
+
- lib/sendle/api/errors/missing_api_key.rb
|
113
|
+
- lib/sendle/api/errors/missing_sendle_id.rb
|
114
|
+
- lib/sendle/api/errors/unauthorized.rb
|
115
|
+
- lib/sendle/api/ping.rb
|
116
|
+
- lib/sendle/api/responses/pong.rb
|
117
|
+
- lib/sendle/api/version.rb
|
118
|
+
- lib/sendle/utils/actions.rb
|
119
|
+
- sendle-api.gemspec
|
120
|
+
- spec/sendle/api/ping_spec.rb
|
121
|
+
- spec/sendle/api_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
- spec/support/helpers.rb
|
124
|
+
- spec/support/shared_examples/with_credentials_spec.rb
|
125
|
+
- tasks/rspec.rake
|
126
|
+
homepage: http://api-doc.sendle.com
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.4.2
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Ruby bindings for the Sendle API
|
150
|
+
test_files:
|
151
|
+
- spec/sendle/api/ping_spec.rb
|
152
|
+
- spec/sendle/api_spec.rb
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
- spec/support/helpers.rb
|
155
|
+
- spec/support/shared_examples/with_credentials_spec.rb
|