sms77 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 621b698c5ea5c6f08f25ebb60d427a949fe8a011de54e82623234d4af10e0c7f
4
- data.tar.gz: 11e68e54c358e93aacb25e6da5289d2fe904b8def5ef86ce9cdd2b1aac68ae35
3
+ metadata.gz: 36eb3f4cd708334c2bda49e4c94c7eef521de326a94231cdfe0c53e76bdee13f
4
+ data.tar.gz: 4ab1e7ec064ee7b3fc3bb8415fe1f8b1b23721bdb786647e88bee187bcc620ac
5
5
  SHA512:
6
- metadata.gz: b86d9e8884dad820fc01892f002c5e90de2162a40dd326c8c95c2cda8a404304924aeb02fc460f79f25aa78089d703662530a5e2995060ff2c8d3c9d4bfb6891
7
- data.tar.gz: b3650f5844d714e1d925aaf31c8fd8e2b73b49c955220096654044239ef0fa978e3b00a3ae6ced2f8b9818825e8da3aa80ab908f79945204112add325abf78b2
6
+ metadata.gz: 0a1cfa14204af7aa47452dedbd5971f1f6d5e839651ef77fcabf94c6ebfc7995d4d78b2a5e77fa73d491bf3adf246fc32afe499919e5d9eddecc4817de6309f4
7
+ data.tar.gz: c7c7631464d9bdc25b84e227d00c6271d46d2ee16e710759e445e457f84e3e212de819401abfbb74d4e5f6cd1cdef338a407e857887a212d9e06923826bc6d1b
data/README.md CHANGED
@@ -3,15 +3,27 @@
3
3
  # Ruby Client for the Sms77.io SMS Gateway API
4
4
 
5
5
  ## Installation
6
-
7
6
  ```gem install sms77```
8
7
 
9
8
  ### Usage
10
-
11
9
  ```ruby
12
10
  require 'sms77'
13
11
 
14
12
  client = Sms77::Client.new(ENV['SMS77_API_KEY'])
15
13
 
16
14
  puts "Balance: #{client.balance}"
17
- ```
15
+ ```
16
+
17
+ #### Testing
18
+ ```shell
19
+ SMS77_API_KEY=MySms77ApiKey bundle exec rspec
20
+ ```
21
+
22
+ *Optional environment variables*
23
+
24
+ Setting ```SMS77_DEBUG=1``` prints details to stdout.
25
+
26
+ Setting ```SMS77_TEST_HTTP=1``` enables live testing with actual API requests.
27
+
28
+ ##### Support
29
+ Need help? Feel free to send us an <a href='mailto: support@sms77.io'>email</a>.
@@ -27,6 +27,10 @@ module Sms77
27
27
  get_or_post(Sms77::Hooks::Action::READ == params[:action], Sms77::Endpoint::HOOKS, params)
28
28
  end
29
29
 
30
+ def journal(params)
31
+ get(Sms77::Endpoint::JOURNAL, params)
32
+ end
33
+
30
34
  def lookup(params)
31
35
  post(Sms77::Endpoint::LOOKUP, params)
32
36
  end
@@ -5,6 +5,7 @@ module Sms77::Endpoint
5
5
  BALANCE = 'balance'
6
6
  CONTACTS = 'contacts'
7
7
  HOOKS = 'hooks'
8
+ JOURNAL = 'journal'
8
9
  LOOKUP = 'lookup'
9
10
  PRICING = 'pricing'
10
11
  SMS = 'sms'
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sms77::Journal
4
+ module Type
5
+ INBOUND = 'inbound'
6
+ OUTBOUND = 'outbound'
7
+ REPLIES = 'replies'
8
+ VOICE = 'voice'
9
+ end
10
+
11
+ module Validator
12
+ def self.validate(params)
13
+ type = params[:type]
14
+ date_from = params[:date_from]
15
+ date_to = params[:date_to]
16
+
17
+ raise "Unknown type #{type}" unless Sms77::Journal::Validator::is_type?(type)
18
+ raise "Wrong date_from #{date_from}" unless Sms77::Journal::Validator::is_date?(date_from)
19
+ raise "Wrong date_to #{date_to}" unless Sms77::Journal::Validator::is_date?(date_to)
20
+ end
21
+
22
+ def self.subscribe(params)
23
+ { :request_method => Sms77::Hooks::RequestMethod::POST }.merge!(params)
24
+
25
+ self.event_type?(params[:event_type]) &&
26
+ self.request_method?(params[:request_method]) &&
27
+ self.target_url?(params[:target_url])
28
+ end
29
+
30
+ def self.is_type?(str)
31
+ Sms77::Util::in_module_constants?(str, Sms77::Journal::Type)
32
+ end
33
+
34
+ def self.is_date?(date)
35
+ date.is_a?(NilClass) || date.match(/[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1])/)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sms77::Sms
4
+ module Type
5
+ DIRECT = 'direct'
6
+ ECONOMY = 'economy'
7
+ end
8
+ end
@@ -25,4 +25,26 @@ module Sms77::Util
25
25
  def self.in_module_constants?(needle, mod)
26
26
  get_module_constant_values(mod).include?(needle)
27
27
  end
28
+
29
+ def self.valid_float?(str)
30
+ !!Float(str) rescue false
31
+ end
32
+
33
+ def self.numeric?(val)
34
+ return true if val.is_a?(Integer)
35
+
36
+ val.scan(/\D/).empty?
37
+ end
38
+
39
+ def self.boolean?(val)
40
+ [true, false].include? val
41
+ end
42
+
43
+ def self.nil_or_lengthy_string?(val)
44
+ val.nil? || (val.is_a?(String) && val.length)
45
+ end
46
+
47
+ def self.lengthy_string?(val)
48
+ return val.is_a?(String) && !val.empty?
49
+ end
28
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sms77
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -5,11 +5,11 @@ require 'sms77/endpoint'
5
5
 
6
6
  RSpec.describe Sms77, 'client' do
7
7
  it 'checks api key' do
8
- expect(Helper.client.api_key).to be_lengthy(String)
8
+ expect(Helper.client.api_key).to be_lengthy_string
9
9
  end
10
10
 
11
11
  it 'checks sentWith' do
12
- expect(Helper.client.sent_with).to be_lengthy(String)
12
+ expect(Helper.client.sent_with).to be_lengthy_string
13
13
  end
14
14
 
15
15
  it 'fails authentication' do
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'sms77/endpoint'
5
+ require 'sms77/journal'
6
+ require 'sms77/sms'
7
+
8
+ RSpec.describe Sms77, 'journal' do
9
+ def valid_timestamp?(str)
10
+ str.match(/[\d]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][\d]|3[0-1]) (2[0-3]|[01][\d]):[0-5][\d]/)
11
+ end
12
+
13
+ def request(type)
14
+ stub = [{
15
+ :from => "SMS",
16
+ :id => "123456789",
17
+ :price => "1.2",
18
+ :text => "Hey my friend!",
19
+ :timestamp => "2020-10-14 14:25:04",
20
+ :to => "49170123456789",
21
+ }]
22
+
23
+ res = Helper.get(Sms77::Endpoint::JOURNAL, stub, { type: type })
24
+
25
+ expect(res).to be_a(Array)
26
+
27
+ res.each do |journal|
28
+ expect(journal).to be_a(Hash)
29
+ expect(journal[:from]).to be_lengthy_string
30
+ expect(journal[:id]).to be_numeric
31
+ expect(Sms77::Util::valid_float?(journal[:price])).to be_truthy
32
+ expect(journal[:text]).to be_lengthy_string
33
+ expect(valid_timestamp?(journal[:timestamp])).to be_truthy
34
+ expect(journal[:to]).to be_lengthy_string
35
+ end
36
+
37
+ res
38
+ end
39
+
40
+ it 'returns all inbound messages' do
41
+ request(Sms77::Journal::Type::INBOUND)
42
+ end
43
+
44
+ it 'returns all outbound messages' do
45
+ request(Sms77::Journal::Type::OUTBOUND).each do |journal|
46
+ journal.merge!({
47
+ :connection => "http",
48
+ :dlr => "DELIVERED",
49
+ :dlr_timestamp => "2020-10-04 09:26:10.000",
50
+ :foreign_id => "MyForeignId",
51
+ :label => "MyCustomLabel",
52
+ :latency => "5.1060",
53
+ :mccmnc => "26207",
54
+ :type => "direct",
55
+ })
56
+ expect(journal[:connection]).to be_lengthy_string
57
+ expect(journal[:dlr]).to be_nil_or_lengthy_string
58
+ expect(valid_timestamp?(journal[:dlr_timestamp])).to be_truthy
59
+ expect(journal[:foreign_id]).to be_nil_or_lengthy_string
60
+ expect(journal[:label]).to be_nil_or_lengthy_string
61
+ expect(journal[:latency]).to be_nil_or_lengthy_string
62
+ expect(journal[:mccmnc]).to be_nil_or_lengthy_string
63
+ expect(Sms77::Util::in_module_constants?(journal[:type], Sms77::Sms::Type)).to be_truthy
64
+ end
65
+ end
66
+
67
+ it 'returns all voice messages' do
68
+ request(Sms77::Journal::Type::VOICE).each do |journal|
69
+ journal.merge!({
70
+ :duration => "2",
71
+ :error => "",
72
+ :status => "completed",
73
+ :xml => false,
74
+ })
75
+ expect(journal[:duration]).to be_numeric
76
+ expect(journal[:error]).to be_nil_or_lengthy_string
77
+ expect(journal[:status]).to be_lengthy_string
78
+ expect(journal[:xml]).to be_boolean
79
+ end
80
+ end
81
+
82
+ it 'returns all reply messages' do
83
+ request(Sms77::Journal::Type::REPLIES)
84
+ end
85
+ end
@@ -5,23 +5,27 @@ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
5
5
  require 'sms77'
6
6
  require 'sms77/util'
7
7
 
8
+ RSpec::Matchers.define :be_nil_or_lengthy_string do
9
+ match do |val|
10
+ Sms77::Util::nil_or_lengthy_string?(val)
11
+ end
12
+ end
13
+
8
14
  RSpec::Matchers.define :be_boolean do
9
- match do |value|
10
- [true, false].include? value
15
+ match do |val|
16
+ Sms77::Util::boolean?(val)
11
17
  end
12
18
  end
13
19
 
14
20
  RSpec::Matchers.define :be_numeric do
15
- match do |value|
16
- return true if value.is_a?(Integer)
17
-
18
- value.scan(/\D/).empty?
21
+ match do |val|
22
+ Sms77::Util::numeric?(val)
19
23
  end
20
24
  end
21
25
 
22
- RSpec::Matchers.define :be_lengthy do
23
- match do |value|
24
- return true if value.is_a?(String) && !Helper.client.sent_with.empty?
26
+ RSpec::Matchers.define :be_lengthy_string do
27
+ match do |val|
28
+ Sms77::Util::lengthy_string?(val)
25
29
  end
26
30
  end
27
31
 
@@ -43,7 +47,7 @@ end
43
47
 
44
48
  class Helper
45
49
  @client = Sms77::Client.new(ENV['SMS77_DUMMY_API_KEY'], 'ruby-test')
46
- @is_http = ENV.key?('TEST_HTTP').freeze
50
+ @is_http = ENV['SMS77_TEST_HTTP'].freeze
47
51
  @stubs = Faraday::Adapter::Test::Stubs.new
48
52
  @virtual_inbound_nr_eplus = '+491771783130'
49
53
  Sms77::Client::BUILDER.adapter(:test, @stubs) unless @is_http
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms77
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sms77 e.K.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,7 +83,9 @@ files:
83
83
  - lib/sms77/contacts.rb
84
84
  - lib/sms77/endpoint.rb
85
85
  - lib/sms77/hooks.rb
86
+ - lib/sms77/journal.rb
86
87
  - lib/sms77/lookup.rb
88
+ - lib/sms77/sms.rb
87
89
  - lib/sms77/util.rb
88
90
  - lib/sms77/version.rb
89
91
  - sms77.gemspec
@@ -91,6 +93,7 @@ files:
91
93
  - spec/sms77/client_spec.rb
92
94
  - spec/sms77/contacts_spec.rb
93
95
  - spec/sms77/hooks_spec.rb
96
+ - spec/sms77/journal_spec.rb
94
97
  - spec/sms77/lookup_spec.rb
95
98
  - spec/sms77/pricing_spec.rb
96
99
  - spec/sms77/sms_spec.rb
@@ -133,3 +136,4 @@ test_files:
133
136
  - spec/sms77/hooks_spec.rb
134
137
  - spec/sms77/balance_spec.rb
135
138
  - spec/sms77/validate_for_voice_spec.rb
139
+ - spec/sms77/journal_spec.rb