checkmobi-sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d15db47851b5f391007395693ee762c44714e530
4
+ data.tar.gz: dcc7470faabd77d75dc100f0f2a94cc63398577f
5
+ SHA512:
6
+ metadata.gz: 268920fb5da798f2ede63e282e02890afc5f450b2d95f36166e354530aa07e5d04b8c6fef434cb96126679ec112436c14ce84bf10e1372ce73a8c897bf169739
7
+ data.tar.gz: 0c4996727bd9411fa362ce65d1f515a621478e05d72d04465b4d3d9e5e9f633f6b0946ff00d8f15b72fa0b9501daf401eaa36e63cec4bb9722ce2e380bade722
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ .rake_tasks~
12
+ # rspec failure tracking
13
+ .rspec_status
14
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.15.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in checkmobi-sdk.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 hexa
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.
@@ -0,0 +1,86 @@
1
+ # Checkmobi::SDK
2
+
3
+ This is Checkmobi Ruby Library
4
+ For additional examples, please see official documentation at [https://checkmobi.com/documentation.html#/overview](https://checkmobi.com/documentation.html#/overview)
5
+
6
+ [![Build Status](https://travis-ci.org/HEXA-UA/checkmobi-sdk.svg?branch=master)](https://travis-ci.org/HEXA-UA/checkmobi-sdk)
7
+ [![Code Climate](https://codeclimate.com/github/HEXA-UA/checkmobi-sdk/badges/gpa.svg)](https://codeclimate.com/github/HEXA-UA/checkmobi-sdk)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'checkmobi-sdk'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install checkmobi-sdk
24
+
25
+ ## Usage
26
+
27
+ For all properties accepted by the following methods check [https://checkmobi.com/documentation.html#/overview](https://checkmobi.com/documentation.html#/overview)
28
+
29
+ ```ruby
30
+ require 'checkmobi'
31
+
32
+ client = Checkmobi::SDK::Client('secret key here')
33
+ api = Checkmobi::SDK::Api.new(client)
34
+
35
+ # get list of countries & flags
36
+ api.account_details
37
+
38
+ # get account details
39
+ api.account_details
40
+
41
+ # get prefixes
42
+ api.prefixes
43
+
44
+ # checking a number for being valid
45
+ response = api.check_number({ :number => '+number here' })
46
+
47
+ # validate a number using "Missed call method". (type can be : sms, ivr, cli, reverse_cli)
48
+ response = api.check_number({ :type => 'sms', :number => '+number here' })
49
+
50
+ # verify a pin for a certain request
51
+ response = api.verify_pin({ :id => "request id here", :pin => "5659" })
52
+
53
+ #check validation status for a certain request
54
+ response = api.validation_status('request id here');
55
+
56
+ # send a custom sms
57
+ response = api.send_sms({ :to => "number here", :text => "message here" });
58
+
59
+ # get details about an SMS
60
+ response = api.sms_details('sms id here');
61
+
62
+ # place a call
63
+ params = { :from => "+number here", :to => "+number here", :events => [{ :action => "speak", :text => "Hello world", :loop => 2, :language => "en-US" }] };
64
+ response = api.place_call(params);
65
+
66
+ # get a call details
67
+ response = api.call_details('call id here');
68
+
69
+ # hangup a call
70
+ response = api.hang_up_call('call id here');
71
+
72
+ ```
73
+
74
+ ## Development
75
+
76
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
77
+
78
+ 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).
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hexa-ua/checkmobi-sdk.
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,21 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc 'Build Gem'
5
+ task :build do
6
+ system 'gem build checkmobi-ruby.gemspec'
7
+ end
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ desc 'Run all tests'
12
+ RSpec::Core::RakeTask.new('spec:all') do |t|
13
+ # t.rscpec_opts = %w(--colour --fortmat documentation)
14
+ # t.pattern = 'spec/**/*_spec.rb'
15
+ end
16
+
17
+ task :default => :spec
18
+
19
+ task :console do
20
+ sh 'pry --gem'
21
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "checkmobi"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,44 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "checkmobi/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'checkmobi-sdk'
8
+ spec.version = Checkmobi::SDK::VERSION
9
+ spec.authors = ['hexa']
10
+ spec.email = ['i.pylypenko@hexa.com.ua']
11
+
12
+ spec.summary = "Checkmobi's Ruby SDK"
13
+ spec.description = "Checkmobi's Ruby SDK for interacting with the Checkmobi API."
14
+ spec.homepage = 'https://hexa.com.ua'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler', '~> 1.15'
34
+ spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rspec', '~> 3.0'
36
+ spec.add_development_dependency 'pry', '~> 0.9'
37
+ spec.add_development_dependency 'pry-byebug', '~> 3.3'
38
+ spec.add_development_dependency 'vcr', '~> 3.0'
39
+ spec.add_development_dependency 'simplecov', '~> 0.11'
40
+ spec.add_development_dependency 'webmock', '~> 1.22'
41
+
42
+ spec.add_dependency 'rest-client', '~> 1.6'
43
+ spec.add_dependency 'json', '~> 1.8'
44
+ end
@@ -0,0 +1,25 @@
1
+ require 'rest_client'
2
+ require 'yaml'
3
+ require 'json'
4
+
5
+ require 'checkmobi/client'
6
+ require 'checkmobi/api'
7
+ require 'checkmobi/response'
8
+ require 'checkmobi/exceptions/exceptions'
9
+
10
+ module Checkmobi
11
+ module SDK
12
+ class << self
13
+
14
+ attr_accessor :api_key
15
+
16
+ def configure
17
+ yield self
18
+ true
19
+ end
20
+
21
+ alias_method :config, :configure
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,59 @@
1
+ module Checkmobi
2
+ module SDK
3
+ class Api
4
+
5
+ def initialize(client = Checkmobi::SDK::Client.new)
6
+ @client = client
7
+ end
8
+
9
+ def account_details
10
+ @client.get '/my-account'
11
+ end
12
+
13
+ def countries
14
+ @client.get '/countries'
15
+ end
16
+
17
+ def prefixes
18
+ @client.get '/prefixes'
19
+ end
20
+
21
+ def send_sms(params)
22
+ @client.post '/sms/send', params
23
+ end
24
+
25
+ def check_number(params)
26
+ @client.post '/checknumber', params
27
+ end
28
+
29
+ def request_validation(params)
30
+ @client.post '/validation/request', params
31
+ end
32
+
33
+ def verify_pin(params)
34
+ @client.post '/validation/verify', params
35
+ end
36
+
37
+ def validation_status(id)
38
+ @client.get "/validation/status/#{id}"
39
+ end
40
+
41
+ def sms_details(id)
42
+ @client.get "/sms/#{id}"
43
+ end
44
+
45
+ def place_call(params)
46
+ @client.post '/call', params
47
+ end
48
+
49
+ def call_details(id)
50
+ @client.get "/call/#{id}"
51
+ end
52
+
53
+ def hang_up_call(id)
54
+ @client.delete "/call/#{id}"
55
+ end
56
+
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,68 @@
1
+ require 'checkmobi/exceptions/exceptions'
2
+
3
+ module Checkmobi
4
+ module SDK
5
+ class Client
6
+
7
+ def initialize(api_key = Checkmobi.api_key,
8
+ api_host = 'api.checkmobi.com',
9
+ api_version = 'v1')
10
+
11
+ endpoint = endpoint_generator(api_host, api_version)
12
+
13
+ @http_client = RestClient::Resource.new(endpoint,
14
+ headers: {
15
+ :Authorization => api_key,
16
+ :content_type => 'application/json'
17
+ })
18
+ end
19
+
20
+ def post(resource_path, data, headers = {})
21
+ response = @http_client[resource_path].post(data.to_json, headers)
22
+ Checkmobi::SDK::Response.new(response)
23
+ rescue => err
24
+ raise communication_error err
25
+ end
26
+
27
+ def get(resource_path, params = nil)
28
+ if params
29
+ response = @http_client[resource_path].get(params: params)
30
+ else
31
+ response = @http_client[resource_path].get()
32
+ end
33
+ Checkmobi::SDK::Response.new(response)
34
+ rescue => err
35
+ raise communication_error err
36
+ end
37
+
38
+ def put(resource_path, data)
39
+ response = @http_client[resource_path].put(data.to_json)
40
+ Checkmobi::SDK::Response.new(response)
41
+ rescue => err
42
+ raise communication_error err
43
+ end
44
+
45
+ def delete(resource_path)
46
+ begin
47
+ response = @http_client[resource_path].delete
48
+ Checkmobi::SDK::Response.new(response)
49
+ rescue => err
50
+ raise communication_error err
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ def endpoint_generator(api_host, api_version)
57
+ scheme = 'https'
58
+ "#{scheme}://#{api_host}/#{api_version}"
59
+ end
60
+
61
+ def communication_error(e)
62
+ return CommunicationError.new(e.message, e.response) if e.respond_to? :response
63
+ CommunicationError.new(e.message)
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,19 @@
1
+ module Checkmobi
2
+ class Error < StandardError
3
+
4
+ attr_reader :object
5
+
6
+ def initialize(message = nil, object = nil)
7
+ super(message)
8
+ @object = object
9
+ end
10
+
11
+ end
12
+
13
+ class CommunicationError < Error
14
+ attr_reader :code
15
+ end
16
+
17
+ class ParseError < Error; end
18
+
19
+ end
@@ -0,0 +1,47 @@
1
+ module Checkmobi
2
+ module SDK
3
+ class Response
4
+
5
+ attr_accessor :body, :code
6
+
7
+ def initialize(response)
8
+ @body = response.body
9
+ @code = response.code
10
+ end
11
+
12
+ def to_h
13
+ JSON.parse(@body)
14
+ rescue => err
15
+ raise err
16
+ end
17
+
18
+ # Replace @body with Ruby Hash
19
+ #
20
+ # @return [Hash] A standard Ruby Hash containing the HTTP result.
21
+ def to_h!
22
+ @body = JSON.parse(@body)
23
+ rescue => err
24
+ raise ParseError.new(err), err
25
+ end
26
+
27
+ # Return response as Yaml
28
+ #
29
+ # @return [String] A string containing response as YAML
30
+ def to_yaml
31
+ YAML.dump(to_h)
32
+ rescue => err
33
+ raise err
34
+ end
35
+
36
+ # Replace @body with YAML
37
+ #
38
+ # @return [String] A string containing response as YAML
39
+ def to_yaml!
40
+ @body = YAML.dump(to_h)
41
+ rescue => err
42
+ raise ParseError.new(err), err
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module Checkmobi
2
+ module SDK
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: checkmobi-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - hexa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-26 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.11'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.11'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.22'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.22'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rest-client
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.6'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.6'
139
+ - !ruby/object:Gem::Dependency
140
+ name: json
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.8'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.8'
153
+ description: Checkmobi's Ruby SDK for interacting with the Checkmobi API.
154
+ email:
155
+ - i.pylypenko@hexa.com.ua
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - bin/console
168
+ - bin/setup
169
+ - checkmobi-sdk.gemspec
170
+ - lib/checkmobi.rb
171
+ - lib/checkmobi/api.rb
172
+ - lib/checkmobi/client.rb
173
+ - lib/checkmobi/exceptions/exceptions.rb
174
+ - lib/checkmobi/response.rb
175
+ - lib/checkmobi/version.rb
176
+ homepage: https://hexa.com.ua
177
+ licenses:
178
+ - MIT
179
+ metadata:
180
+ allowed_push_host: https://rubygems.org
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.6.11
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Checkmobi's Ruby SDK
201
+ test_files: []