check_mobi 1.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.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +15 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +1 -0
  7. data/Gemfile +4 -0
  8. data/Guardfile +42 -0
  9. data/LICENSE.txt +22 -0
  10. data/README.md +37 -0
  11. data/Rakefile +11 -0
  12. data/check_mobi.gemspec +31 -0
  13. data/lib/check_mobi/client.rb +65 -0
  14. data/lib/check_mobi/configuration.rb +44 -0
  15. data/lib/check_mobi/core_ext/hash.rb +11 -0
  16. data/lib/check_mobi/core_ext/string.rb +15 -0
  17. data/lib/check_mobi/errors/required_field_error.rb +3 -0
  18. data/lib/check_mobi/resource.rb +37 -0
  19. data/lib/check_mobi/resources/check_number.rb +20 -0
  20. data/lib/check_mobi/resources/country_list.rb +19 -0
  21. data/lib/check_mobi/resources/my_account.rb +17 -0
  22. data/lib/check_mobi/resources/phone_validation/request_validation.rb +22 -0
  23. data/lib/check_mobi/resources/phone_validation/validation_status.rb +21 -0
  24. data/lib/check_mobi/resources/phone_validation/verify_pin.rb +23 -0
  25. data/lib/check_mobi/resources/prefixes.rb +17 -0
  26. data/lib/check_mobi/resources/sms/details.rb +23 -0
  27. data/lib/check_mobi/resources/sms/send.rb +23 -0
  28. data/lib/check_mobi/resources/voice/actions/hangup.rb +17 -0
  29. data/lib/check_mobi/resources/voice/actions/play.rb +21 -0
  30. data/lib/check_mobi/resources/voice/actions/send_dtmf.rb +22 -0
  31. data/lib/check_mobi/resources/voice/actions/speak.rb +22 -0
  32. data/lib/check_mobi/resources/voice/actions/wait.rb +22 -0
  33. data/lib/check_mobi/resources/voice/call.rb +26 -0
  34. data/lib/check_mobi/resources/voice/call_details.rb +24 -0
  35. data/lib/check_mobi/resources/voice/events.rb +32 -0
  36. data/lib/check_mobi/resources/voice/hangup_call.rb +24 -0
  37. data/lib/check_mobi/response.rb +22 -0
  38. data/lib/check_mobi/shared/class_with_attributes.rb +102 -0
  39. data/lib/check_mobi/version.rb +3 -0
  40. data/lib/check_mobi.rb +45 -0
  41. data/test/check_mobi/check_mobi_test.rb +7 -0
  42. data/test/check_mobi/client_test.rb +64 -0
  43. data/test/check_mobi/configuration_test.rb +55 -0
  44. data/test/check_mobi/core_ext/hash_test.rb +7 -0
  45. data/test/check_mobi/core_ext/string_test.rb +27 -0
  46. data/test/check_mobi/resources/check_number_test.rb +35 -0
  47. data/test/check_mobi/resources/country_test.rb +14 -0
  48. data/test/check_mobi/resources/my_account_test.rb +15 -0
  49. data/test/check_mobi/resources/phone_validation/request_validation_test.rb +47 -0
  50. data/test/check_mobi/resources/phone_validation/validation_status_test.rb +24 -0
  51. data/test/check_mobi/resources/phone_validation/verify_pin_test.rb +27 -0
  52. data/test/check_mobi/resources/prefix_test.rb +15 -0
  53. data/test/check_mobi/resources/sms/detail_test.rb +24 -0
  54. data/test/check_mobi/resources/sms/send_test.rb +57 -0
  55. data/test/check_mobi/resources/voice/actions/hangup_action_test.rb +42 -0
  56. data/test/check_mobi/resources/voice/actions/play_action_test.rb +25 -0
  57. data/test/check_mobi/resources/voice/actions/send_dtmf_action_test.rb +29 -0
  58. data/test/check_mobi/resources/voice/actions/speak_action_test.rb +76 -0
  59. data/test/check_mobi/resources/voice/actions/wait_action_test.rb +26 -0
  60. data/test/check_mobi/resources/voice/call_details_test.rb +16 -0
  61. data/test/check_mobi/resources/voice/call_test.rb +147 -0
  62. data/test/check_mobi/resources/voice/hangup_call_test.rb +16 -0
  63. data/test/check_mobi/shared/class_with_attributes_test.rb +136 -0
  64. data/test/helper.rb +42 -0
  65. metadata +271 -0
@@ -0,0 +1,26 @@
1
+ require_relative '../../resource'
2
+ require_relative '../../shared/class_with_attributes'
3
+
4
+ module CheckMobi
5
+ module Resources
6
+ module Voice
7
+
8
+ class Call < Resource
9
+
10
+ attributes :from, :to, :notification_callback, :platform
11
+ attribute :events, default: []
12
+
13
+ private
14
+
15
+ def defaults
16
+ super.merge!({
17
+ rel_path: '/call',
18
+ http_method: ALLOWED_METHODS[1],
19
+ form_data: to_hash
20
+ })
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../../resource'
2
+ require_relative '../../shared/class_with_attributes'
3
+
4
+ module CheckMobi
5
+ module Resources
6
+ module Voice
7
+
8
+ class CallDetails < Resource
9
+
10
+ attributes :id
11
+
12
+ private
13
+
14
+ def defaults
15
+ super.merge!({
16
+ rel_path: "/call/#{@id}",
17
+ http_method: ALLOWED_METHODS[0]
18
+ })
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ require_relative '../../shared/class_with_attributes'
2
+
3
+ module CheckMobi
4
+ module Resources
5
+ module Voice
6
+ class Events
7
+ include ClassWithAttributes
8
+
9
+ readonly_attributes :action
10
+
11
+ def to_hash
12
+ super.merge({action: action})
13
+ end
14
+
15
+ private
16
+
17
+ def after_initialize # overridden by subclasses
18
+ @action = self.class.name.split('::').last.underscore!
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ # class << self
26
+ # attr_reader :required_fields
27
+ #
28
+ # def mandatory_fields(*args)
29
+ # @required_fields = []
30
+ # args.each {|field| @required_fields << field}
31
+ # end
32
+ # end
@@ -0,0 +1,24 @@
1
+ require_relative '../../resource'
2
+ require_relative '../../shared/class_with_attributes'
3
+
4
+ module CheckMobi
5
+ module Resources
6
+ module Voice
7
+
8
+ class HangupCall < Resource
9
+
10
+ attributes :req_id
11
+
12
+ private
13
+
14
+ def defaults
15
+ super.merge!({
16
+ rel_path: "/call/#{@req_id}",
17
+ http_method: ALLOWED_METHODS[2]
18
+ })
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ require 'ostruct'
2
+ require 'json'
3
+ require 'forwardable'
4
+ require_relative '../../lib/check_mobi/errors/required_field_error'
5
+ require_relative '../../lib/check_mobi/client'
6
+
7
+ module CheckMobi
8
+ class Response
9
+
10
+ extend Forwardable
11
+
12
+ def_delegators :@http_client, :status_code, :is_successful, :body, :response, :code
13
+ def_delegator :response, :body, :response_body
14
+
15
+ alias_method :reason, :body
16
+
17
+ def initialize(http_client)
18
+ raise RequiredFieldError, 'parameter should be a CheckMobi::Client, which is missing' unless http_client.kind_of? CheckMobi::Client
19
+ @http_client = http_client
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,102 @@
1
+ module ClassWithAttributes
2
+ def self.included(base)
3
+ base.extend ClassMethods
4
+ end
5
+
6
+ module ClassMethods
7
+
8
+ def attributes(*vars)
9
+ @attributes ||= []
10
+
11
+ vars.uniq.each do |var|
12
+ @attributes << {name: var, default: nil}
13
+ end
14
+
15
+ send :include, InstanceMethods unless included_modules.include?(InstanceMethods)
16
+ attr_accessor *vars
17
+ end
18
+
19
+ def readonly_attributes(*vars)
20
+ @attributes ||= []
21
+
22
+ vars.uniq.each do |var|
23
+ @attributes << {name: var, default: nil}
24
+ end
25
+
26
+ send :include, InstanceMethods unless included_modules.include?(InstanceMethods)
27
+ attr_reader *vars
28
+ end
29
+
30
+ def attribute(name, options={})
31
+ @attributes ||= []
32
+
33
+ @attributes << ({name: name, default: options[:default]})
34
+
35
+ send :include, InstanceMethods unless included_modules.include?(InstanceMethods)
36
+ attr_accessor name
37
+ end
38
+
39
+ def readonly_attribute(name, options={})
40
+ @attributes ||= []
41
+
42
+ @attributes << ({name: name, default: options[:default]})
43
+
44
+ send :include, InstanceMethods unless included_modules.include?(InstanceMethods)
45
+ attr_reader name
46
+ end
47
+
48
+ end
49
+
50
+ module InstanceMethods
51
+
52
+ def attributes
53
+ self.class.instance_variable_get(:@attributes).map{|e| e[:name]}
54
+ end
55
+
56
+ def initialize(options = {})
57
+ attributes = (self.class.instance_variable_get(:@attributes) || []).map{|e| [e[:name], e[:default].dup]}
58
+
59
+ attributes.each do |name, val|
60
+ if respond_to?("#{name}=") and options.include?(name)
61
+ value = options[name]
62
+ else
63
+ value = val
64
+ end
65
+
66
+ instance_variable_set("@#{name}", value)
67
+ end
68
+
69
+ after_initialize if respond_to?(:after_initialize, true)
70
+ end
71
+
72
+ def update_attributes(options= {})
73
+ valid_options = options.select { |k,v| attributes.map(&:to_s).include?(k.to_s) }
74
+ valid_options.each {|k,v| public_send("#{k}=", v) if respond_to?("#{k}=")}
75
+ end
76
+
77
+ def to_hash
78
+ h = {}
79
+ attributes.each do |attr|
80
+ value = public_send(attr)
81
+ if value.is_a? Array
82
+ values = []
83
+ value.each do |val|
84
+ if val.respond_to?(:to_hash)
85
+ values << val.to_hash
86
+ else
87
+ values << val
88
+ end
89
+ end
90
+ h[attr] = values
91
+ elsif value.respond_to?(:to_hash)
92
+ h[attr] = value.to_hash
93
+ else
94
+ h[attr] = value
95
+ end
96
+ end
97
+
98
+ return h
99
+ end
100
+
101
+ end
102
+ end
@@ -0,0 +1,3 @@
1
+ module CheckMobi
2
+ VERSION = "1.0.1"
3
+ end
data/lib/check_mobi.rb ADDED
@@ -0,0 +1,45 @@
1
+ require_relative 'check_mobi/configuration'
2
+ require_relative 'check_mobi/core_ext/string'
3
+ require_relative 'check_mobi/core_ext/hash'
4
+
5
+ $:.unshift File.expand_path(File.dirname(__FILE__))
6
+
7
+ module CheckMobi
8
+
9
+ autoload :Client, 'check_mobi/client'
10
+ autoload :Response, 'check_mobi/response'
11
+
12
+ module Resources
13
+ autoload :CountryList, 'check_mobi/resources/country_list'
14
+ autoload :CheckNumber, 'check_mobi/resources/check_number'
15
+ autoload :Prefixes, 'check_mobi/resources/prefixes'
16
+ autoload :MyAccount, 'check_mobi/resources/my_account'
17
+
18
+ module SMS
19
+ autoload :Send, 'check_mobi/resources/sms/send'
20
+ autoload :Details, 'check_mobi/resources/sms/details'
21
+ end
22
+
23
+ module PhoneValidation
24
+ autoload :RequestValidation, 'check_mobi/resources/phone_validation/request_validation'
25
+ autoload :ValidationStatus, 'check_mobi/resources/phone_validation/validation_status'
26
+ autoload :VerifyPin, 'check_mobi/resources/phone_validation/verify_pin'
27
+ end
28
+
29
+ module Voice
30
+ autoload :Call, 'check_mobi/resources/voice/call'
31
+ autoload :CallDetails, 'check_mobi/resources/voice/call_details'
32
+ autoload :HangupCall, 'check_mobi/resources/voice/hangup_call'
33
+
34
+ module Actions
35
+ autoload :Hangup, 'check_mobi/resources/voice/actions/hangup'
36
+ autoload :Play, 'check_mobi/resources/voice/actions/play'
37
+ autoload :SendDTMF, 'check_mobi/resources/voice/actions/send_dtmf'
38
+ autoload :Speak, 'check_mobi/resources/voice/actions/speak'
39
+ autoload :Wait, 'check_mobi/resources/voice/actions/wait'
40
+ end
41
+ end
42
+ end
43
+
44
+ extend Configuration
45
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ describe CheckMobi do
4
+ it 'should have a version' do
5
+ CheckMobi::VERSION.wont_be_nil
6
+ end
7
+ end
@@ -0,0 +1,64 @@
1
+ require 'helper'
2
+ require 'json'
3
+
4
+ describe CheckMobi::Client do
5
+ let(:form_data) { {'sample_data': 1} }
6
+
7
+ describe 'In Common' do
8
+ before do
9
+ CheckMobi.configure do |c|
10
+ c.content_type = 'json'
11
+ c.accept_type = 'json'
12
+ c.api_key = '1234567'
13
+ end
14
+
15
+ @client = CheckMobi::Client.new()
16
+ end
17
+
18
+ after do
19
+ CheckMobi.reset
20
+ end
21
+
22
+ it 'should have valid headers' do
23
+ @client.headers['Content-Type'].must_equal CheckMobi.content_type
24
+ @client.headers['Accept'].must_equal CheckMobi.accept_type
25
+ @client.headers['Authorization'].must_equal CheckMobi.api_key
26
+ end
27
+ end
28
+
29
+ describe 'On HTTP GET' do
30
+
31
+ before do
32
+ @client = CheckMobi::Client.new(http_method: :get)
33
+ @request = @client.request
34
+ end
35
+
36
+ it 'should return instance of net/http/get instance' do
37
+ @request.must_be_instance_of Net::HTTP::Get
38
+ end
39
+
40
+ it 'wont accept/return form_data' do
41
+ @client.send(:set_body, form_data)
42
+ @request.body.must_equal nil
43
+ end
44
+
45
+ end
46
+
47
+ describe "On HTTP POST" do
48
+
49
+ before do
50
+ @client = CheckMobi::Client.new(http_method: :post)
51
+ @request = @client.request
52
+ end
53
+
54
+ it "should return instance of net/http/get instance" do
55
+ @request.must_be_instance_of Net::HTTP::Post
56
+ end
57
+
58
+ it "should accept/return form_data" do
59
+ @client.send(:set_body, form_data)
60
+ JSON.parse(@request.body).symbolize_keys.must_equal form_data
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,55 @@
1
+ require 'helper'
2
+
3
+ describe 'configuration' do
4
+
5
+ before do
6
+ CheckMobi.reset
7
+ end
8
+
9
+ describe '.api_key' do
10
+ it 'should return default key' do
11
+ CheckMobi.api_key.must_equal CheckMobi::Configuration::DEFAULT_API_KEY
12
+ end
13
+ end
14
+
15
+ describe '.format' do
16
+ it 'should return default fomat' do
17
+ CheckMobi.format.must_equal CheckMobi::Configuration::DEFAULT_FORMAT
18
+ end
19
+ end
20
+
21
+ describe '.method' do
22
+ it 'should return default method' do
23
+ CheckMobi.method.must_equal CheckMobi::Configuration::DEFAULT_METHOD
24
+ end
25
+ end
26
+
27
+ describe '.user_agent' do
28
+ it 'should return default user agent' do
29
+ CheckMobi.user_agent.must_equal CheckMobi::Configuration::DEFAULT_USER_AGENT
30
+ end
31
+ end
32
+
33
+ CheckMobi::Configuration::VALID_CONFIG_KEYS.each do |key|
34
+ describe ".#{key}" do
35
+ it 'should return the default value' do
36
+ CheckMobi.send(key).must_equal CheckMobi::Configuration.const_get("DEFAULT_#{key.upcase}")
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '.configure' do
42
+ CheckMobi::Configuration::VALID_CONFIG_KEYS.each do |key|
43
+ it "should set the #{key}" do
44
+ CheckMobi.configure do |config|
45
+ config.send("#{key}=", key)
46
+ CheckMobi.send(key).must_equal key
47
+ end # CheckMobi.configure
48
+ end # describe 'it should set the key'
49
+ end # CheckMobi::Configuration::VALID_CONFIG_KEYS
50
+ end # describe '.configure'
51
+
52
+ after do
53
+ CheckMobi.reset
54
+ end
55
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ describe Hash do
4
+ it 'should symbolize_keys' do
5
+ {'a': 1, "b": 2}.symbolize_keys.must_equal({a: 1, b: 2})
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ require 'helper'
2
+ require_relative '../../../lib/check_mobi/core_ext/string'
3
+
4
+ describe String do
5
+
6
+ it 'should respond to underscore' do
7
+ 'TheSampleClass'.must_respond_to(:underscore)
8
+ 'TheSampleClass'.must_respond_to(:underscore!)
9
+ end
10
+
11
+ it 'should underscore a class string name' do
12
+ 'TheSampleClass'.underscore.must_equal 'the_sample_class'
13
+ 'TheSampleClass'.underscore!.must_equal 'the_sample_class'
14
+ end
15
+
16
+ it 'should put / on namespacing' do
17
+ 'SuperTop::Parent::TheSampleClass'.underscore.must_equal 'super_top/parent/the_sample_class'
18
+ end
19
+
20
+ it 'should preserve /' do
21
+ 'SuperTop/Parent/TheSampleClass'.underscore.must_equal 'super_top/parent/the_sample_class'
22
+ end
23
+
24
+ it 'should replace - with _' do
25
+ 'Super-Top/Parent/The-Sample-Class'.underscore.must_equal 'super_top/parent/the_sample_class'
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ require 'helper'
2
+
3
+ describe CheckMobi::Resources::CheckNumber do
4
+ before do
5
+ CheckMobi.api_key = ENV['API_KEY']
6
+ @endpoint = 'https://api.checkmobi.com/v1/checknumber'
7
+ @resource_class = CheckMobi::Resources::CheckNumber
8
+ stub_post_request(@endpoint)
9
+ end
10
+
11
+ it 'should request without phone number' do
12
+ resource = @resource_class.new
13
+ response = resource.perform
14
+ assert_requested(:post, @endpoint, headers: headers_with_authorization, body: {number: nil}.to_json, times: 1)
15
+ end
16
+
17
+ it 'should request with invalid phone number' do
18
+ resource = @resource_class.new(phone_number: '000000000')
19
+ resource.perform
20
+ assert_requested(:post, @endpoint, headers: headers_with_authorization, body: {number: '000000000'}.to_json, times: 1)
21
+ end
22
+
23
+ it 'should request without api key' do
24
+ CheckMobi.api_key = nil
25
+ resource = @resource_class.new(phone_number: ENV['PHONE_NUMBER'])
26
+ resource.perform
27
+ assert_requested(:post, @endpoint, headers: headers_without_authorization, body: {number: ENV['PHONE_NUMBER']}.to_json, times: 1)
28
+ end
29
+
30
+ it 'should request with api key and phone number' do
31
+ resource = @resource_class.new(phone_number: ENV['PHONE_NUMBER'])
32
+ resource.perform
33
+ assert_requested(:post, @endpoint, headers: headers_with_authorization, body: {number: ENV['PHONE_NUMBER']}.to_json, times: 1)
34
+ end
35
+ end
@@ -0,0 +1,14 @@
1
+ require 'helper'
2
+
3
+ describe CheckMobi::Resources::CountryList do
4
+ before do
5
+ @endpoint = 'https://api.checkmobi.com/v1/countries'
6
+ stub_get_request(@endpoint)
7
+ end
8
+
9
+ it "should request country list" do
10
+ @resource = CheckMobi::Resources::CountryList.new
11
+ @resource.perform
12
+ assert_requested(:get, @endpoint, headers: headers_without_authorization, times: 1)
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require 'helper'
2
+
3
+ describe CheckMobi::Resources::MyAccount do
4
+ before do
5
+ CheckMobi.api_key = ENV['API_KEY']
6
+ @endpoint = 'https://api.checkmobi.com/v1/my-account'
7
+ stub_get_request(@endpoint)
8
+ end
9
+
10
+ it 'should fetch account info with valid api_key' do
11
+ resource = CheckMobi::Resources::MyAccount.new
12
+ resource.perform
13
+ assert_requested(:get, @endpoint, headers: headers_with_authorization, times: 1)
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ require 'helper'
2
+
3
+ describe CheckMobi::Resources::PhoneValidation::RequestValidation do
4
+ before do
5
+ @endpoint = 'https://api.checkmobi.com/v1/validation/request'
6
+
7
+ CheckMobi.configure do |c|
8
+ c.api_key = ENV['API_KEY']
9
+ end
10
+
11
+ @resource = CheckMobi::Resources::PhoneValidation::RequestValidation.new(
12
+ number: ENV['PHONE_NUMBER'],
13
+ type: 'cli',
14
+ language: 'en-US'
15
+ )
16
+
17
+ stub_post_request(@endpoint)
18
+ end
19
+
20
+ describe 'phone validation resource' do
21
+
22
+ it 'should request with no phone number' do
23
+ @resource.number = nil
24
+ @resource.perform
25
+ assert_requested(:post,
26
+ @endpoint,
27
+ headers: headers_with_authorization,
28
+ body: { number: nil, type: 'cli', language: 'en-US', notification_callback:nil, platform: "web"},
29
+ times: 1)
30
+ end
31
+
32
+ it 'should request with all valid fields' do
33
+ CheckMobi.api_key = ENV['API_KEY']
34
+ @resource.type = 'reverse_cli'
35
+ @resource.perform
36
+ assert_requested(:post,
37
+ @endpoint,
38
+ headers: headers_with_authorization,
39
+ body: { number: ENV['PHONE_NUMBER'], type: 'reverse_cli', language: 'en-US',
40
+ notification_callback:nil, platform: "web"},
41
+ times: 1)
42
+ end
43
+
44
+ end
45
+
46
+
47
+ end
@@ -0,0 +1,24 @@
1
+ require 'helper'
2
+
3
+ describe CheckMobi::Resources::PhoneValidation::ValidationStatus do
4
+ before do
5
+ @id = 'xxxxxx'
6
+ @endpoint = "https://api.checkmobi.com/v1/validation/status/#{@id}"
7
+
8
+ CheckMobi.configure do |c|
9
+ c.api_key = ENV['API_KEY']
10
+ end
11
+
12
+ @resource = CheckMobi::Resources::PhoneValidation::ValidationStatus.new
13
+ stub_get_request(@endpoint)
14
+ end
15
+
16
+ it 'validation status resource should request properly' do
17
+ @resource.id = @id
18
+ @resource.perform
19
+ assert_requested(:get,
20
+ @endpoint,
21
+ headers: headers_with_authorization,
22
+ times: 1)
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ require 'helper'
2
+
3
+ describe CheckMobi::Resources::PhoneValidation::VerifyPin do
4
+ before do
5
+ @pin = 'xxxxxx'
6
+ @id = 'sid'
7
+ @endpoint = 'https://api.checkmobi.com/v1/validation/verify'
8
+
9
+ CheckMobi.configure do |c|
10
+ c.api_key = ENV['API_KEY']
11
+ end
12
+
13
+ @resource = CheckMobi::Resources::PhoneValidation::VerifyPin.new
14
+ stub_post_request(@endpoint)
15
+ end
16
+
17
+ it 'validation status resource should request properly' do
18
+ @resource.update_attributes(pin: @pin, id: @id)
19
+ @resource.perform
20
+ assert_requested(:post,
21
+ @endpoint,
22
+ body: {pin: @pin, id: @id, use_server_hangup: false},
23
+ headers: headers_with_authorization,
24
+ times: 1)
25
+ end
26
+
27
+ end
@@ -0,0 +1,15 @@
1
+ require 'helper'
2
+
3
+ describe CheckMobi::Resources::Prefixes do
4
+ before do
5
+ CheckMobi.api_key = ENV['API_KEY']
6
+ @endpoint = 'https://api.checkmobi.com/v1/prefixes'
7
+ end
8
+
9
+ it 'should fetch prefixes' do
10
+ stub_get_request(@endpoint)
11
+ resource = CheckMobi::Resources::Prefixes.new
12
+ resource.perform
13
+ assert_requested(:get, @endpoint, headers: headers_with_authorization, times: 1)
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ require 'helper'
2
+
3
+ describe CheckMobi::Resources::SMS::Details do
4
+ before do
5
+ @endpoint = "https://api.checkmobi.com/v1/sms/"
6
+ @sms_id = '123456'
7
+ CheckMobi.api_key = ENV['API_KEY']
8
+ @resource_class = CheckMobi::Resources::SMS::Details
9
+ stub_get_request(@endpoint)
10
+ stub_get_request(@endpoint + @sms_id)
11
+ end
12
+
13
+ it 'with invalid id' do
14
+ client = @resource_class.new(id: nil)
15
+ client.perform
16
+ assert_requested(:get, @endpoint, headers: headers_with_authorization, times: 1)
17
+ end
18
+
19
+ it 'sms details fetching should be successful' do
20
+ client = @resource_class.new(id: @sms_id)
21
+ client.perform
22
+ assert_requested(:get, @endpoint + @sms_id, headers: headers_with_authorization, times: 1)
23
+ end
24
+ end