clx_rest_api 0.1.0
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 +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +53 -0
- data/LICENSE.txt +21 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/clx_rest_api.gemspec +37 -0
- data/lib/clx_rest_api/base_uri.rb +3 -0
- data/lib/clx_rest_api/client.rb +15 -0
- data/lib/clx_rest_api/configuration.rb +10 -0
- data/lib/clx_rest_api/endpoint_dsl.rb +15 -0
- data/lib/clx_rest_api/request.rb +50 -0
- data/lib/clx_rest_api/response.rb +13 -0
- data/lib/clx_rest_api/uri_interpretation.rb +26 -0
- data/lib/clx_rest_api/version.rb +3 -0
- data/lib/clx_rest_api.rb +14 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 58035f9ed4775ae2a7ab6734a70a9ac6a4deeba4
|
4
|
+
data.tar.gz: 4706b13a3fc23e92df9078fef2e3a10999599c50
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12a080d345b2af7046a7cdd5c4c1d97a2677ca397b19aa5bda5f3baa51244e079e1ec056930b4305c327d6e0cafe9a21f89686a13328f07f2ffd63be31808b6e
|
7
|
+
data.tar.gz: 01ee28d8bbb70fd65a73ce0ef39cca67a9970ae659da44d288ddd5a71823b181cf676f39b4c902c32a22edbba2e8b2fdaf71a3badac25df71454655a0be70924
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
clx_rest_api (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.5.2)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
coderay (1.1.2)
|
12
|
+
crack (0.4.3)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
hashdiff (0.3.7)
|
16
|
+
method_source (0.9.0)
|
17
|
+
pry (0.11.3)
|
18
|
+
coderay (~> 1.1.0)
|
19
|
+
method_source (~> 0.9.0)
|
20
|
+
public_suffix (3.0.1)
|
21
|
+
rake (10.5.0)
|
22
|
+
rspec (3.7.0)
|
23
|
+
rspec-core (~> 3.7.0)
|
24
|
+
rspec-expectations (~> 3.7.0)
|
25
|
+
rspec-mocks (~> 3.7.0)
|
26
|
+
rspec-core (3.7.1)
|
27
|
+
rspec-support (~> 3.7.0)
|
28
|
+
rspec-expectations (3.7.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.7.0)
|
31
|
+
rspec-mocks (3.7.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.7.0)
|
34
|
+
rspec-support (3.7.1)
|
35
|
+
safe_yaml (1.0.4)
|
36
|
+
webmock (3.3.0)
|
37
|
+
addressable (>= 2.3.6)
|
38
|
+
crack (>= 0.3.2)
|
39
|
+
hashdiff
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
bundler (~> 1.16)
|
46
|
+
clx_rest_api!
|
47
|
+
pry
|
48
|
+
rake (~> 10.0)
|
49
|
+
rspec (~> 3.0)
|
50
|
+
webmock (~> 3.3)
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Emric
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# CLXRestAPI
|
2
|
+
Made for creating easy integration with the CLX Rest API.
|
3
|
+
You can find their API documentation [here](https://www.clxcommunications.com/docs/sms/http-rest.html).
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'clx_rest_api'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install clx_rest_api
|
19
|
+
|
20
|
+
## Configuration
|
21
|
+
To use the API you need a service plan id and a token.
|
22
|
+
Use the configuration block to set these.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
CLXRestAPI.configure do |config|
|
26
|
+
config.service_plan_id = "my_service_plan_id"
|
27
|
+
config.api_token = "my_api_token"
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
To use the API create an instance of the `CLXRestAPI::Client` class.
|
33
|
+
You can send a request to an endpoint like this:
|
34
|
+
```ruby
|
35
|
+
client = CLXRestAPI::Client.new
|
36
|
+
client.send_batch_message(params: {})
|
37
|
+
```
|
38
|
+
|
39
|
+
This returns a `CLXRestAPI::Response` instance.
|
40
|
+
```ruby
|
41
|
+
# Contains the response body parsed from JSON
|
42
|
+
response.body
|
43
|
+
|
44
|
+
# Contains a Net::HTTP response for further debugging
|
45
|
+
response.original_response
|
46
|
+
```
|
47
|
+
|
48
|
+
## Available endpoints
|
49
|
+
As of now these are the available endpoints:
|
50
|
+
- :send_batch_messsage, docs: https://www.clxcommunications.com/docs/sms/http-rest.html#send-a-batch-message
|
51
|
+
- :retrieve_delivery_report, docs: https://www.clxcommunications.com/docs/sms/http-rest.html#retrieve-a-delivery-report
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
56
|
+
|
57
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
58
|
+
|
59
|
+
To define a new endpoint for the client you can use the provided DSL:
|
60
|
+
```ruby
|
61
|
+
define_endpoint :my_endpoint, :get, "/my_url/:my_param/
|
62
|
+
```
|
63
|
+
|
64
|
+
`:my_param` will be fetched from the arguments provided when doing the method call.
|
65
|
+
|
66
|
+
## Contributing
|
67
|
+
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/standout/clx_rest_api.
|
69
|
+
|
70
|
+
## License
|
71
|
+
|
72
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "clx_rest_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "clx_rest_api/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "clx_rest_api"
|
8
|
+
spec.version = CLXRestAPI::VERSION
|
9
|
+
spec.authors = ["Emric"]
|
10
|
+
spec.email = ["w.e.w@live.se"]
|
11
|
+
|
12
|
+
spec.summary = "CLX rest API integration"
|
13
|
+
spec.homepage = "https://www.github.com/standout/clx-rest-api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://www.rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_development_dependency "webmock", "~> 3.3"
|
36
|
+
spec.add_development_dependency "pry"
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "clx_rest_api/uri_interpretation"
|
2
|
+
require "clx_rest_api/endpoint_dsl"
|
3
|
+
|
4
|
+
module CLXRestAPI
|
5
|
+
class Client
|
6
|
+
extend EndpointDSL
|
7
|
+
|
8
|
+
define_endpoint :send_batch_message, :post, "/batches"
|
9
|
+
define_endpoint :retrieve_delivery_report, :get, "/batches/:batch_id/delivery_report"
|
10
|
+
|
11
|
+
def initialize(config = CLXRestAPI.config)
|
12
|
+
@config = config
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "clx_rest_api/uri_interpretation"
|
2
|
+
require "clx_rest_api/request"
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
module CLXRestAPI
|
6
|
+
module EndpointDSL
|
7
|
+
def define_endpoint(name, method, uri)
|
8
|
+
define_method(name) do |args = {}|
|
9
|
+
uri = URIInterpretation.new(uri, OpenStruct.new(args), config: @config).to_s
|
10
|
+
request = CLXRestAPI::Request.new(uri, method: method, config: @config)
|
11
|
+
request.execute(args[:params])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "clx_rest_api/response"
|
2
|
+
require "net/https"
|
3
|
+
require "net/http"
|
4
|
+
require "json"
|
5
|
+
|
6
|
+
module CLXRestAPI
|
7
|
+
class Request
|
8
|
+
attr_reader :uri
|
9
|
+
|
10
|
+
def initialize(uri, method: :get, config: CLXRestAPI.config)
|
11
|
+
@config = config
|
12
|
+
@method = method
|
13
|
+
@uri = URI(uri)
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute(body = {})
|
17
|
+
response = http.request http_request(body)
|
18
|
+
Response.new(response)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def http
|
24
|
+
@http ||= Net::HTTP.new(uri.host, uri.port)
|
25
|
+
@http.tap do |protocol|
|
26
|
+
protocol.use_ssl = true
|
27
|
+
protocol.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def http_request(body)
|
32
|
+
send "#{@method}_request", body
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_request(body)
|
36
|
+
@uri.query = URI.encode_www_form(body)
|
37
|
+
Net::HTTP::Get.new(@uri).tap do |req|
|
38
|
+
req["Authorization"] = "Bearer #{@config.api_token}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def post_request(body)
|
43
|
+
Net::HTTP::Post.new(@uri).tap do |req|
|
44
|
+
req["Authorization"] = "Bearer #{@config.api_token}"
|
45
|
+
req.content_type = "application/json"
|
46
|
+
req.body = body.to_json
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "clx_rest_api/base_uri"
|
2
|
+
|
3
|
+
module CLXRestAPI
|
4
|
+
class URIInterpretation
|
5
|
+
def initialize(uri, param_receiver, config: CLXRestAPI.config)
|
6
|
+
@service_plan_id = config.service_plan_id
|
7
|
+
@param_receiver = param_receiver
|
8
|
+
@uri = uri
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
suffix = @uri.gsub(param_regex) {|param| retrieve_param(param) }
|
13
|
+
"#{CLXRestAPI::BASE_URI}/xms/v1/#{@service_plan_id}#{suffix}"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def param_regex
|
19
|
+
/(?<=\/):(\w*)/
|
20
|
+
end
|
21
|
+
|
22
|
+
def retrieve_param(param)
|
23
|
+
@param_receiver[param[/\w+/]]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/clx_rest_api.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "clx_rest_api/configuration"
|
2
|
+
require "clx_rest_api/version"
|
3
|
+
require "clx_rest_api/client"
|
4
|
+
|
5
|
+
module CLXRestAPI
|
6
|
+
class << self
|
7
|
+
attr_accessor :config
|
8
|
+
|
9
|
+
def configure
|
10
|
+
self.config ||= Configuration.new
|
11
|
+
yield(config)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clx_rest_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emric
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-16 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
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
|
+
description:
|
84
|
+
email:
|
85
|
+
- w.e.w@live.se
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- clx_rest_api.gemspec
|
101
|
+
- lib/clx_rest_api.rb
|
102
|
+
- lib/clx_rest_api/base_uri.rb
|
103
|
+
- lib/clx_rest_api/client.rb
|
104
|
+
- lib/clx_rest_api/configuration.rb
|
105
|
+
- lib/clx_rest_api/endpoint_dsl.rb
|
106
|
+
- lib/clx_rest_api/request.rb
|
107
|
+
- lib/clx_rest_api/response.rb
|
108
|
+
- lib/clx_rest_api/uri_interpretation.rb
|
109
|
+
- lib/clx_rest_api/version.rb
|
110
|
+
homepage: https://www.github.com/standout/clx-rest-api
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata:
|
114
|
+
allowed_push_host: https://www.rubygems.org
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.6.8
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: CLX rest API integration
|
135
|
+
test_files: []
|