skuby 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3a7223daf23c2b544211d00cf23ef18b4105817
4
- data.tar.gz: fb4b363f23d4e9b3f8d7e0c0fc71082ff3594254
3
+ metadata.gz: 5f12a818c34ac6ec0a049df74d619b9958b41251
4
+ data.tar.gz: 26ae01e0da07a5737bfc46ca17515d0993627fa5
5
5
  SHA512:
6
- metadata.gz: f3d95b18eba653c4003c5aecc6ef129977028ddd6b0c1dbb9c209805442749cc70c0d6dc155749d90ddb995b903f033416e9b5befc346c0b9c1c3a0609189edf
7
- data.tar.gz: e619a585c8b796bbe002c74aaaf4b947a9a79423202d493ee17fc06d24ab7aeccc722cfc90475f874df51293dbf420a23cea8e4edbafb5fb07958cdc46eb5627
6
+ metadata.gz: 3ab2e7826d9278ad9b7717cff589cb04c16c73ce93416beedfe6fb0e322270accd7314331cb2922b9d2c66b30a7ac49d1a67b94650b9b46d7d4d2dfbacae23e3
7
+ data.tar.gz: e999cd80bccf59e8180443f963e10ca14e39a25bc52866c32d701b85358793aa2cd98b2014c3cbedfd7c8a5e5b7d5e3f44cf228eafb44be8405918a0a94ebc76
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/welaika/skuby.png?branch=master)](https://travis-ci.org/welaika/skuby)
4
4
  [![Coverage Status](https://coveralls.io/repos/welaika/skuby/badge.png)](https://coveralls.io/r/welaika/skuby)
5
+ [![Code Climate](https://codeclimate.com/github/welaika/skuby.png)](https://codeclimate.com/github/welaika/skuby)
5
6
  [![Dependency Status](https://gemnasium.com/welaika/skuby.png)](https://gemnasium.com/welaika/skuby)
6
7
 
7
8
  A Ruby interface for Skebby
@@ -0,0 +1,10 @@
1
+ ---
2
+ method: notify
3
+ skebby_dispatch_id: '666'
4
+ skebby_message_id: '777'
5
+ recipient: '393471234567'
6
+ status: DELIVERED
7
+ error_code: '1'
8
+ user_reference: '12345'
9
+ skebby_date_time: Mon, 19 Feb 2012 17:52:01 +0000
10
+ operator_date_time: Mon, 19 Feb 2012 17:51:01 +0000
@@ -0,0 +1,10 @@
1
+ ---
2
+ method: notify
3
+ skebby_dispatch_id: '444'
4
+ skebby_message_id: '333'
5
+ recipient: '393471234567'
6
+ status: UNDELIVERABLE
7
+ error_code: '502'
8
+ user_reference: '12345'
9
+ skebby_date_time: Mon, 15 Aug 2005 15:52:01 +0000
10
+ operator_date_time: Mon, 15 Aug 2005 15:51:01 +0000
@@ -5,7 +5,7 @@ module Skuby
5
5
 
6
6
  def self.send_sms(text = '', recipients = '')
7
7
  params = build_params(text, recipients)
8
- SmsResponse.new(self.post('', body: params))
8
+ SMSResponse.new(self.post('', body: params), text, recipients)
9
9
  end
10
10
 
11
11
  def self.build_params(text, recipients)
@@ -44,10 +44,6 @@ module Skuby
44
44
  status == "DELIVERED"
45
45
  end
46
46
 
47
- def failure?
48
- !success?
49
- end
50
-
51
47
  def status
52
48
  @raw["status"]
53
49
  end
@@ -65,7 +61,7 @@ module Skuby
65
61
  end
66
62
 
67
63
  def delivered_at
68
- @raw["operator_date_time"]
64
+ Time.parse(@raw["operator_date_time"])
69
65
  end
70
66
 
71
67
  end
@@ -1,41 +1,39 @@
1
1
  module Skuby
2
- class SmsResponse
3
- attr_reader :raw
2
+ class SMSResponse
3
+ attr_reader :response, :text, :recipients
4
4
 
5
- def initialize(query)
6
- @raw = CGI.parse(query)
5
+ def initialize(response, text, recipients)
6
+ @response = CGI.parse(response)
7
+ @text = text
8
+ @recipients = Array(recipients)
7
9
  end
8
10
 
9
11
  def success?
10
12
  status == "success"
11
13
  end
12
14
 
13
- def failed?
14
- !success?
15
- end
16
-
17
15
  def sms_id?
18
16
  sms_id.present?
19
17
  end
20
18
 
21
19
  def status
22
- @raw["status"].first
20
+ @response["status"].first
23
21
  end
24
22
 
25
23
  def remaining_sms
26
- @raw["remaining_sms"].first.to_i
24
+ @response["remaining_sms"].first.to_i
27
25
  end
28
26
 
29
27
  def sms_id
30
- @raw["id"].first
28
+ @response["id"].first
31
29
  end
32
30
 
33
31
  def error_code
34
- @raw["code"].first.to_i
32
+ @response["code"].first.to_i
35
33
  end
36
34
 
37
35
  def error_message
38
- @raw["message"].first
36
+ @response["message"].first
39
37
  end
40
38
 
41
39
  end
@@ -1,3 +1,3 @@
1
1
  module Skuby
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -12,7 +12,7 @@ describe Skuby::Credit do
12
12
 
13
13
  context "::balance" do
14
14
  it "returns balance in euro" do
15
- VCR.use_cassette('get_credit', match_requests_on: [:body]) do
15
+ VCR.use_cassette('get_credit') do
16
16
  request = Skuby::Credit.balance
17
17
  expect(request).to eq(9.49)
18
18
  end
@@ -22,7 +22,7 @@ describe Skuby::Credit do
22
22
  before { Skuby.setup do |config| config.password = 'wrong_password' end }
23
23
 
24
24
  it "returns nil if something's wrong" do
25
- VCR.use_cassette('get_credit_wrong_credentials', match_requests_on: [:body]) do
25
+ VCR.use_cassette('get_credit_wrong_credentials') do
26
26
  expect(Skuby::Credit.balance).to be_nil
27
27
  end
28
28
  end
@@ -14,11 +14,13 @@ describe Skuby::Gateway do
14
14
  before { Skuby.setup do |config| config.method = 'send_sms_classic' end }
15
15
 
16
16
  it "successfully send an sms" do
17
- VCR.use_cassette('send_sms_classic', match_requests_on: [:body]) do
17
+ VCR.use_cassette('send_sms_classic') do
18
18
  response = Skuby::Gateway.send_sms('Lorem ipsum', '393290000000')
19
19
  expect(response.success?).to be_true
20
20
  expect(response.sms_id?).to be_false
21
21
  expect(response.remaining_sms).to eq(152)
22
+ expect(response.text).to eq('Lorem ipsum')
23
+ expect(response.recipients).to eq(['393290000000'])
22
24
  end
23
25
  end
24
26
  end
@@ -27,11 +29,13 @@ describe Skuby::Gateway do
27
29
  before { Skuby.setup do |config| config.method = 'send_sms_basic' end }
28
30
 
29
31
  it "successfully send an sms" do
30
- VCR.use_cassette('send_sms_basic', match_requests_on: [:body]) do
32
+ VCR.use_cassette('send_sms_basic') do
31
33
  response = Skuby::Gateway.send_sms('Lorem ipsum', '393290000000')
32
34
  expect(response.success?).to be_true
33
35
  expect(response.sms_id?).to be_false
34
36
  expect(response.remaining_sms).to eq(207)
37
+ expect(response.text).to eq('Lorem ipsum')
38
+ expect(response.recipients).to eq(['393290000000'])
35
39
  end
36
40
  end
37
41
  end
@@ -40,12 +44,14 @@ describe Skuby::Gateway do
40
44
  before { Skuby.setup do |config| config.method = 'send_sms_classic_report' end }
41
45
 
42
46
  it "successfully send an sms" do
43
- VCR.use_cassette('send_sms_classic_report', match_requests_on: [:body]) do
47
+ VCR.use_cassette('send_sms_classic_report') do
44
48
  response = Skuby::Gateway.send_sms('Lorem ipsum', '393290000000')
45
49
  expect(response.success?).to be_true
46
50
  expect(response.sms_id?).to be_true
47
51
  expect(response.sms_id).to eq('64608933')
48
52
  expect(response.remaining_sms).to eq(150)
53
+ expect(response.text).to eq('Lorem ipsum')
54
+ expect(response.recipients).to eq(['393290000000'])
49
55
  end
50
56
  end
51
57
  end
@@ -55,11 +61,13 @@ describe Skuby::Gateway do
55
61
 
56
62
  context "no recipient" do
57
63
  it "returns an error" do
58
- VCR.use_cassette('send_sms_no_recipient', match_requests_on: [:body]) do
64
+ VCR.use_cassette('send_sms_no_recipient') do
59
65
  response = Skuby::Gateway.send_sms('Lorem ipsum')
60
66
  expect(response.success?).to be_false
61
67
  expect(response.error_code).to eq(25)
62
68
  expect(response.error_message).to be_present
69
+ expect(response.text).to eq('Lorem ipsum')
70
+ expect(response.recipients).to eq([""])
63
71
  end
64
72
  end
65
73
  end
@@ -68,11 +76,13 @@ describe Skuby::Gateway do
68
76
  before { Skuby.setup do |config| config.password = 'wrong_password' end }
69
77
 
70
78
  it "returns an error" do
71
- VCR.use_cassette('send_sms_wrong_credentials', match_requests_on: [:body]) do
79
+ VCR.use_cassette('send_sms_wrong_credentials') do
72
80
  response = Skuby::Gateway.send_sms('Lorem ipsum', '393290000000')
73
81
  expect(response.success?).to be_false
74
82
  expect(response.error_code).to eq(21)
75
83
  expect(response.error_message).to be_present
84
+ expect(response.text).to eq('Lorem ipsum')
85
+ expect(response.recipients).to eq(['393290000000'])
76
86
  end
77
87
  end
78
88
  end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+ require 'yaml'
3
+
4
+ describe Skuby::Report do
5
+ let(:report) { Skuby::Report.new(params) }
6
+
7
+ context "with errors" do
8
+ let(:params) { YAML.load(File.open(fixture_for_skebby_report('error.yaml'))) }
9
+
10
+ it "parses skebby response" do
11
+ expect(report.success?).to be_false
12
+ expect(report.error_code).to eq(502)
13
+ expect(report.error_message).to be_present
14
+ expect(report.sms_id).to eq('333')
15
+ expect(report.delivered_at).to eq(Time.new(2005,8,15,17,51,1))
16
+ end
17
+ end
18
+
19
+ context "without errors" do
20
+ let(:params) { YAML.load(File.open(fixture_for_skebby_report('delivered.yaml'))) }
21
+
22
+ it "parses skebby response" do
23
+ expect(report.success?).to be_true
24
+ expect(report.sms_id).to eq('777')
25
+ expect(report.delivered_at).to eq(Time.new(2012,2,19,18,51,1))
26
+ end
27
+ end
28
+
29
+ def fixture_for_skebby_report(name)
30
+ File.join(File.dirname(__FILE__), '..', 'fixtures', 'skebby_report', name)
31
+ end
32
+
33
+ end
34
+
@@ -20,6 +20,7 @@ RSpec.configure do |config|
20
20
  end
21
21
 
22
22
  VCR.configure do |c|
23
+ c.default_cassette_options = { match_requests_on: [:method, :uri, :body] }
23
24
  c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
24
25
  c.hook_into :webmock
25
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skuby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabrizio Monti
@@ -166,6 +166,8 @@ files:
166
166
  - LICENSE.txt
167
167
  - README.md
168
168
  - Rakefile
169
+ - fixtures/skebby_report/delivered.yaml
170
+ - fixtures/skebby_report/error.yaml
169
171
  - lib/skuby.rb
170
172
  - lib/skuby/configuration.rb
171
173
  - lib/skuby/credit.rb
@@ -183,6 +185,7 @@ files:
183
185
  - spec/fixtures/vcr_cassettes/send_sms_no_recipient.yml
184
186
  - spec/fixtures/vcr_cassettes/send_sms_wrong_credentials.yml
185
187
  - spec/gateway_spec.rb
188
+ - spec/report_spec.rb
186
189
  - spec/spec_helper.rb
187
190
  homepage: https://github.com/welaika/skuby
188
191
  licenses:
@@ -218,5 +221,6 @@ test_files:
218
221
  - spec/fixtures/vcr_cassettes/send_sms_no_recipient.yml
219
222
  - spec/fixtures/vcr_cassettes/send_sms_wrong_credentials.yml
220
223
  - spec/gateway_spec.rb
224
+ - spec/report_spec.rb
221
225
  - spec/spec_helper.rb
222
226
  has_rdoc: