messagebird-texter 0.0.2 → 0.1.0

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: cf440b4e60686b98901f49458beb54cc1821b141
4
- data.tar.gz: 3aa3f9861a936d7f9d4855ccd2596a50ae3bdd14
3
+ metadata.gz: fc07ab86ed3cb2975eac7d34b645179ed9ba5ee1
4
+ data.tar.gz: c17963495165769db57330e4d5fe667612aa304b
5
5
  SHA512:
6
- metadata.gz: 57c4f2f8da6c5c03e97f2e44b175377a20c1cf8a965ee9c8bfbea14e9aec446a1f4ad44941de7b5c0bf818d667d67b04009281047b01d0daeba7e9584f428546
7
- data.tar.gz: 79a947dcc2293ac3e69f64254ed1a3cf768ae36a5dcc003a0836c6304eded9238ec9e476310a5f161fb6edf4d70a79d9c1587389224e5d09747eee2ec48498a9
6
+ metadata.gz: eb0554ccb0a830bbbd1a0f9066b9cef9c58873336e8b6fb7fc5af36c9fd3d7d6772c10c8104e95f190cdbfa679931c189e1a364c1f614d6a8bf9f07071409c97
7
+ data.tar.gz: 5a127efb3cd3bb2d99e5c372308ff3e04126d97a52bf655fee288f9d999ed3410492d23a91df69a865ac0bf8937623698ed4c87be0bbd28047fb60d8c0557294
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- messagebird-texter (0.0.1)
4
+ messagebird-texter (0.1.0)
5
5
  action-texter
6
6
  phony (~> 2.12)
7
7
 
@@ -12,6 +12,7 @@ GEM
12
12
  json
13
13
  phony (~> 2.12)
14
14
  addressable (2.3.8)
15
+ coderay (1.1.0)
15
16
  coveralls (0.8.5)
16
17
  json (~> 1.8)
17
18
  rest-client (>= 1.6.8, < 2)
@@ -28,9 +29,14 @@ GEM
28
29
  http-cookie (1.0.2)
29
30
  domain_name (~> 0.5)
30
31
  json (1.8.3)
32
+ method_source (0.8.2)
31
33
  mime-types (2.99)
32
34
  netrc (0.11.0)
33
35
  phony (2.15.10)
36
+ pry (0.10.3)
37
+ coderay (~> 1.1.0)
38
+ method_source (~> 0.8.1)
39
+ slop (~> 3.4)
34
40
  rake (10.4.2)
35
41
  rest-client (1.8.0)
36
42
  http-cookie (>= 1.0.2, < 2.0)
@@ -55,6 +61,7 @@ GEM
55
61
  json (~> 1.8)
56
62
  simplecov-html (~> 0.10.0)
57
63
  simplecov-html (0.10.0)
64
+ slop (3.6.0)
58
65
  term-ansicolor (1.3.2)
59
66
  tins (~> 1.0)
60
67
  thor (0.19.1)
@@ -74,6 +81,7 @@ DEPENDENCIES
74
81
  bundler (~> 1.10)
75
82
  coveralls
76
83
  messagebird-texter!
84
+ pry
77
85
  rake (~> 10.0)
78
86
  rspec (~> 3.0)
79
87
  simplecov
data/README.md CHANGED
@@ -1,31 +1,33 @@
1
1
  ![alt text](http://www.hitfoxgroup.com/downloads/hitfox_logo_with_tag_two_colors_WEB.png "Logo Hitfox Group")
2
2
 
3
3
 
4
- messagebird-sms
4
+ messagebird-texter
5
5
  =======
6
6
 
7
7
 
8
8
  Description
9
9
  -----------
10
10
 
11
- Send text messages by means of the HTTP protocol with the service of https://www.messagebird.com, from your ruby app.
12
-
11
+ Create ActionMailer-like notifiers to send messages via the Messagebird REST API
12
+
13
+
13
14
  Usage
14
15
  ------------
15
16
 
16
- ### Configuration
17
+ ### Configure the messenger
17
18
 
18
- Use `MessagebirdTexter.configure` to set `product_token`, `endpoint` and `path`
19
+ Use `MessagebirdTexter.configure` to set `product_token`, `endpoint` and `path`.
19
20
 
20
21
  ```ruby
21
22
  MessagebirdTexter.configure do |config|
22
- config.product_token = 'YOUR_MESSAGEBIRD_API_TOKEN'
23
- config.endpoint = 'https://rest.messagebird.com' # Messagebird default
24
- config.path = '/messages' # Messagebird default
23
+ config.product_token = 'YOUR_MESSAGEBIRD_API_TOKEN'
24
+ config.endpoint = 'https://rest.messagebird.com'
25
+ config.path = '/messages'
25
26
  end
26
27
  ```
27
28
 
28
- Create a class that is inherited from `MessagebirdTexter::Messenger`.
29
+ ### Create a messanger class
30
+ Create a class and inherit from `MessagebirdTexter::Messenger`.
29
31
 
30
32
  ```ruby
31
33
  class TextMessageNotifier < MessagebirdTexter::Messenger
@@ -33,11 +35,10 @@ end
33
35
  ```
34
36
 
35
37
  Now you can add your first welcome message.
36
- This can be as simple as:
37
38
 
38
39
  ```ruby
39
40
  class TextMessageNotifier < MessagebirdTexter::Messenger
40
- default from: 'some string or mobile number'
41
+ default from: 'Hitfox'
41
42
 
42
43
  def welcome(recipient)
43
44
  @recipient = recipient
@@ -64,18 +65,71 @@ end
64
65
 
65
66
  In order to send your sms, you simply call the method and then call `deliver_now` on the return value.
66
67
 
67
- Calling the method returns a MessagebirdTexter Message object:
68
+ Calling the method returns a `MessagebirdTexter::Message` object:
69
+
68
70
  ```ruby
69
71
  message = TextMessageNotifier.welcome(User.first) # => Returns a MessagebirdTexter::Message object
70
- message.deliver_now
72
+ response = message.deliver_now
73
+ ```
74
+
75
+ ### Response Example
76
+ Delivering a message returns a `MessagebirdTexter::Response` object.
77
+
78
+ ####On success
79
+
80
+ ```ruby
81
+ => response.body
82
+ => <MessagebirdTexter::Response::Body:0x007faaca1cfe90
83
+ @content="Some text",
84
+ @created_datetime="2015-12-09T21:43:23+00:00",
85
+ @datacoding="plain",
86
+ @direction="mt",
87
+ @gateway=10,
88
+ @href="https://rest.messagebird.com/messages/bd9e796045668a07b0bca95b78482250",
89
+ @id="bd9e796045668a07b0bca95b78482250",
90
+ @mclass=1,
91
+ @originator="me",
92
+ @recipients=
93
+ {:totalCount=>1,
94
+ :totalSentCount=>1,
95
+ :totalDeliveredCount=>0,
96
+ :totalDeliveryFailedCount=>0,
97
+ :items=>
98
+ [{:recipient=>491759332902, :status=>"sent", :statusDatetime=>"2015-12-09T21:43:23+00:00"}]},
99
+ @reference=nil,
100
+ @scheduled_datetime=nil,
101
+ @type="sms",
102
+ @validity=nil>
103
+
104
+ => response.body.recipients
105
+ => <OpenStruct total_count=1,
106
+ total_sent_count=1,
107
+ total_delivered_count=0,
108
+ items=[
109
+ #<OpenStruct recipient=491759332902,
110
+ status="sent",
111
+ status_datetime=#<Date: 2015-12-09 ((2457366j,0s,0n),+0s,2299161j)>>]>
112
+
113
+ ```
114
+
115
+ ###On failure
116
+
117
+ ```ruby
118
+ => response.error
119
+ => <MessagebirdTexter::Response::Error:0x007fa3d0c39738
120
+ @errors=[{:code=>25, :description=>"Not enough balance", :parameter=>nil}]>
71
121
  ```
72
122
 
123
+
124
+
125
+
126
+
73
127
  Installation
74
128
  ------------
75
129
 
76
- If you user bundler, then just add
130
+ If you use bundler, then just add
77
131
  ```ruby
78
- $ gem 'messagebird-sms'
132
+ $ gem 'messagebird-texter'
79
133
  ```
80
134
  to your Gemfile and execute
81
135
  ```
@@ -83,23 +137,33 @@ $ bundle install
83
137
  ```
84
138
  or without bundler
85
139
  ```
86
- $ gem install messagebird-sms
140
+ $ gem install messagebird-texter
87
141
  ```
88
142
 
89
143
  Upgrade
90
144
  -------
91
145
  ```
92
- $ bundle update messagebird-sms
146
+ $ bundle update messagebird-texter
93
147
  ```
94
148
  or without bundler
95
149
 
96
150
  ```
97
- $ gem update messagebird-sms
151
+ $ gem update messagebird-texter
98
152
  ```
99
153
 
100
154
  Changelog
101
155
  ---------
102
156
 
157
+ ###0.0.1 (2015-12-09)
158
+ Intilial release
159
+
160
+ ###0.0.2 (2015-12-10)
161
+ Minor fixes, readme update
162
+
163
+ ###0.1.0 (2015-12-10)
164
+ - Completly remove validators, api handles errors
165
+ - readme update
166
+
103
167
  ## Contributing
104
168
 
105
169
  Bug reports and pull requests are welcome on GitHub at https://github.com/HitFox/messagebird-sms. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -6,8 +6,8 @@ module MessagebirdTexter
6
6
 
7
7
  module VERSION
8
8
  MAJOR = 0
9
- MINOR = 0
10
- TINY = 2
9
+ MINOR = 1
10
+ TINY = 0
11
11
  PRE = nil
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -1,5 +1,4 @@
1
1
  require 'json'
2
- require 'messagebird_texter/validator/message'
3
2
 
4
3
  module MessagebirdTexter
5
4
  class Message < ActionTexter::Message
@@ -11,10 +10,12 @@ module MessagebirdTexter
11
10
  JSON.generate(recipients: to,
12
11
  originator: from,
13
12
  body: body)
13
+
14
+
14
15
  end
15
16
 
16
17
  def valid?
17
- MessagebirdTexter::Validator::Message.new self
18
+ true
18
19
  end
19
20
  end
20
21
  end
@@ -1,5 +1,4 @@
1
1
  require 'messagebird_texter/response'
2
- require 'messagebird_texter/validator/request'
3
2
 
4
3
  module MessagebirdTexter
5
4
  class Request < ActionTexter::Request
@@ -15,16 +14,11 @@ module MessagebirdTexter
15
14
  end
16
15
 
17
16
  def perform
18
- return unless valid?
19
17
  uri = URI.parse(@endpoint)
20
18
  Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
21
19
  @response = Response.new(http.post(@path, body, 'Authorization' => "AccessKey #{@api_key}", 'Content-Type' => 'application/json'))
22
20
  end
23
21
  response
24
22
  end
25
-
26
- def valid?
27
- MessagebirdTexter::Validator::Request.new
28
- end
29
23
  end
30
24
  end
@@ -19,21 +19,21 @@ module MessagebirdTexter
19
19
  :recipients
20
20
 
21
21
  def initialize(body)
22
- @parsed_body = JSON.parse(body, symbolize_names: true)
23
- @id = @parsed_body[:id]
24
- @href = @parsed_body[:href]
25
- @direction = @parsed_body[:direction]
26
- @type = @parsed_body[:type]
27
- @originator = @parsed_body[:originator]
28
- @content = @parsed_body[:body]
29
- @reference = @parsed_body[:reference]
30
- @validity = @parsed_body[:validity]
31
- @gateway = @parsed_body[:gateway]
32
- @datacoding = @parsed_body[:datacoding]
33
- @mclass = @parsed_body[:mclass]
34
- @scheduled_datetime = @parsed_body[:scheduledDatetime]
35
- @created_datetime = @parsed_body[:createdDatetime]
36
- @recipients = @parsed_body[:recipients]
22
+ parsed_body = JSON.parse(body, symbolize_names: true)
23
+ @id = parsed_body[:id]
24
+ @href = parsed_body[:href]
25
+ @direction = parsed_body[:direction]
26
+ @type = parsed_body[:type]
27
+ @originator = parsed_body[:originator]
28
+ @content = parsed_body[:body]
29
+ @reference = parsed_body[:reference]
30
+ @validity = parsed_body[:validity]
31
+ @gateway = parsed_body[:gateway]
32
+ @datacoding = parsed_body[:datacoding]
33
+ @mclass = parsed_body[:mclass]
34
+ @scheduled_datetime = parsed_body[:scheduledDatetime]
35
+ @created_datetime = parsed_body[:createdDatetime]
36
+ @recipients = parsed_body[:recipients]
37
37
  end
38
38
 
39
39
  def scheduled_datetime
@@ -54,6 +54,8 @@ module MessagebirdTexter
54
54
  ) unless @recipients.nil?
55
55
  end
56
56
 
57
+ private
58
+
57
59
  def items
58
60
  @recipients[:items].map do |i|
59
61
  OpenStruct.new(item(i))
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency 'rake', '~> 10.0'
24
24
  spec.add_development_dependency 'rspec', '~> 3.0'
25
25
  spec.add_development_dependency 'webmock', '~> 1.0'
26
+ spec.add_development_dependency 'pry'
26
27
 
27
28
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0')
28
29
  spec.add_runtime_dependency 'phony', '~> 2.12'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messagebird-texter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - oliverzeyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-09 00:00:00.000000000 Z
11
+ date: 2015-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.0'
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'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: phony
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -122,8 +136,6 @@ files:
122
136
  - lib/messagebird_texter/response.rb
123
137
  - lib/messagebird_texter/response/body.rb
124
138
  - lib/messagebird_texter/response/error.rb
125
- - lib/messagebird_texter/validator/message.rb
126
- - lib/messagebird_texter/validator/request.rb
127
139
  - lib/messagebird_texter/version.rb
128
140
  - messagebird-sms.gemspec
129
141
  homepage: https://github.com/HitFox/messagebird-sms
@@ -1,57 +0,0 @@
1
- require 'phony'
2
- module MessagebirdTexter
3
- module Validator
4
- class Message
5
- class FromTooLong < ArgumentError; end
6
- class FromMissing < ArgumentError; end
7
- class ToMissing < ArgumentError; end
8
- class BodyMissing < ArgumentError; end
9
- class BodyTooLong < ArgumentError; end
10
- class ToUnplausible < ArgumentError; end
11
-
12
- attr_reader :message
13
-
14
- def initialize(message)
15
- @message = message
16
- validate
17
- end
18
-
19
- def validate
20
- fail FromMissing, 'The value for the from attribute is missing.' unless sender_present?
21
- fail FromTooLong, 'The value for the sender attribute must contain 1..11 characters.' unless sender_length?
22
- fail ToMissing, 'The value for the to attribute is missing.' unless receiver_present?
23
- fail BodyMissing, 'The body of the message is missing.' unless body_present?
24
- fail BodyTooLong, 'The body of the message has a length greater than 160.' unless body_correct_length?
25
- fail ToUnplausible, "The given value for the to attribute is not a plausible phone number.\nMaybe the country code is missing." unless receiver_plausible?
26
- end
27
-
28
- def receiver_plausible?
29
- receiver_present? && Phony.plausible?(message.to)
30
- end
31
-
32
- def receiver_present?
33
- !message.to.nil? && !message.to.empty?
34
- end
35
-
36
- def sender_present?
37
- !message.from.nil? && !message.from.empty?
38
- end
39
-
40
- def sender_length?
41
- sender_present? && message.from.length <= 11
42
- end
43
-
44
- def body_present?
45
- !message.body.nil? && !message.body.empty?
46
- end
47
-
48
- def body_correct_length?
49
- body_present? && message.body.length <= 160
50
- end
51
-
52
- def product_token_present?
53
- !MessagebirdTexter.config.product_token.nil? && !MessagebirdTexter.config.product_token.empty?
54
- end
55
- end
56
- end
57
- end
@@ -1,25 +0,0 @@
1
- module MessagebirdTexter
2
- module Validator
3
- class Request
4
- class ProductTokenMissing < ArgumentError; end
5
- class EndpointMissing < ArgumentError; end
6
- class PathMissing < ArgumentError; end
7
- class ContentTypeMissing < ArgumentError; end
8
-
9
- def initialize
10
- @endpoint = MessagebirdTexter.config.endpoint
11
- @path = MessagebirdTexter.config.path
12
- @content_type = MessagebirdTexter.config.content_type
13
- @api_key = MessagebirdTexter.config.product_token
14
- validate
15
- end
16
-
17
- def validate
18
- fail EndpointMissing, "Please provide an valid api endpoint.\nIf you leave this config blank, the default will be set to https://rest.sms-service.org ." if @endpoint.nil? || @endpoint.empty?
19
- fail ContentTypeMissing, 'Please provide a valid content_type! Defaults to application/json' if @content_type.nil? || @content_type.empty?
20
- fail PathMissing, "Please provide an valid api path.\nIf you leave this config blank, the default will be set to /message." if @path.nil? || @path.empty?
21
- fail ProductTokenMissing, "Please provide an valid product key.\nAfter signup at https://www.messagebird.com/, you will find one in your settings." if @api_key.nil?
22
- end
23
- end
24
- end
25
- end