fortytwoish 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +24 -13
- data/lib/fortytwoish.rb +5 -13
- data/lib/fortytwoish/client.rb +16 -17
- data/lib/fortytwoish/version.rb +1 -1
- metadata +3 -3
- data/lib/fortytwoish/configuration.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 199bf04cb32a72f5e709d526f643f59af3b5ef073b37e749af136e673064686e
|
4
|
+
data.tar.gz: 6281f726836f484cab6088baccc3b8d413241a37958ff0e7b8900faa6b8ca356
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ea9ee50d9edbaae1fb5c376a2aa1e4b9c6d199a46a52ccca52ebcc61359217dd393e20740c5cc648559806221c81bc9469d41140ab6cd069f541598a6afd242
|
7
|
+
data.tar.gz: 9a082f0f10177244c80076a1685d65b80b29f16196dc3a62c758575075d68ab09aee4e669bd9761582ba281cb8ed6f0705271a134ba89267cd406d378b9468a3
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -18,15 +18,15 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install fortytwoish
|
20
20
|
|
21
|
-
##
|
21
|
+
## Client
|
22
22
|
|
23
|
-
You can
|
23
|
+
You can create and configurate a client:
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
Fortytwoish.
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
client = Fortytwoish::Client.new(
|
27
|
+
token: 'XXX',
|
28
|
+
encoding: 'GSM7' # GSM7, UCS2, BINARY are available, GSM7 is default
|
29
|
+
)
|
30
30
|
```
|
31
31
|
|
32
32
|
## Usage
|
@@ -34,9 +34,26 @@ end
|
|
34
34
|
Here is example usage of this gem:
|
35
35
|
|
36
36
|
```ruby
|
37
|
-
|
37
|
+
if client.send('15415553010', 'hello, world!') != '200' # send returns '200' in case of success
|
38
|
+
puts client.response_body # response_body contains detail about failed sending
|
39
|
+
end
|
38
40
|
```
|
39
41
|
|
42
|
+
You can send a message to multiple numbers at the same time:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
numbers = %w[
|
46
|
+
15415553010
|
47
|
+
15415553011
|
48
|
+
15415553012
|
49
|
+
]
|
50
|
+
if client.send(numbers, 'hello, world!') != '200' # send returns '200' in case of success
|
51
|
+
puts client.response_body # response_body contains detail about failed sending
|
52
|
+
end
|
53
|
+
```
|
54
|
+
|
55
|
+
*Note:* In case of multiple numbers sendout the results will be `fail` if at least one message failed.
|
56
|
+
|
40
57
|
## Development
|
41
58
|
|
42
59
|
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.
|
@@ -47,12 +64,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
47
64
|
|
48
65
|
Bug reports and pull requests are welcome on GitHub at https://github.com/RushPlay/fortytwoish.
|
49
66
|
|
50
|
-
## Release notes
|
51
|
-
|
52
|
-
### 0.3.0
|
53
|
-
|
54
|
-
* Configurable encoding added
|
55
|
-
|
56
67
|
## License
|
57
68
|
|
58
69
|
MIT
|
data/lib/fortytwoish.rb
CHANGED
@@ -1,18 +1,10 @@
|
|
1
1
|
require 'fortytwoish/version'
|
2
2
|
require 'fortytwoish/client'
|
3
|
-
require 'fortytwoish/configuration'
|
4
3
|
|
5
4
|
module Fortytwoish
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@configuration = nil
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.configure
|
15
|
-
self.configuration ||= Configuration.new
|
16
|
-
yield(configuration)
|
17
|
-
end
|
5
|
+
ALLOWED_ENCODINGS = [
|
6
|
+
GSM7 = 'GSM7',
|
7
|
+
UCS2 = 'UCS2',
|
8
|
+
BINARY = 'BINARY'
|
9
|
+
]
|
18
10
|
end
|
data/lib/fortytwoish/client.rb
CHANGED
@@ -3,46 +3,45 @@ require 'json'
|
|
3
3
|
|
4
4
|
module Fortytwoish
|
5
5
|
class Client
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
attr_reader :response_body
|
7
|
+
|
8
|
+
def initialize(token:, encoding: GSM7)
|
9
|
+
@token = token
|
10
|
+
@encoding = encoding
|
9
11
|
end
|
10
12
|
|
11
|
-
def send
|
12
|
-
response = send_message
|
13
|
+
def send(numbers, message)
|
14
|
+
response = send_message(numbers, message)
|
15
|
+
@response_body = response.body
|
13
16
|
response.code
|
14
17
|
end
|
15
18
|
|
16
19
|
private
|
17
20
|
|
18
|
-
attr_reader :
|
19
|
-
|
20
|
-
def configuration
|
21
|
-
@configuration ||= Fortytwoish.configuration
|
22
|
-
end
|
21
|
+
attr_reader :token, :encoding
|
23
22
|
|
24
|
-
def send_message
|
23
|
+
def send_message(numbers, message)
|
25
24
|
uri = URI 'https://rest.fortytwo.com/1/im'
|
26
|
-
request = build_request(uri)
|
25
|
+
request = build_request(uri, numbers, message)
|
27
26
|
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
28
27
|
http.request request
|
29
28
|
end
|
30
29
|
end
|
31
30
|
|
32
|
-
def build_request(uri)
|
31
|
+
def build_request(uri, numbers, message)
|
33
32
|
request = Net::HTTP::Post.new(uri.path)
|
34
33
|
request['Content-Type'] = 'application/json; charset=utf-8'
|
35
|
-
request['Authorization'] = "Token #{
|
36
|
-
request.body = body
|
34
|
+
request['Authorization'] = "Token #{token}"
|
35
|
+
request.body = body(numbers, message)
|
37
36
|
request
|
38
37
|
end
|
39
38
|
|
40
|
-
def body
|
39
|
+
def body(numbers, message)
|
41
40
|
{
|
42
41
|
destinations: numbers.map { |number| { number: number } },
|
43
42
|
sms_content: {
|
44
43
|
message: message,
|
45
|
-
encoding:
|
44
|
+
encoding: encoding
|
46
45
|
}
|
47
46
|
}.to_json
|
48
47
|
end
|
data/lib/fortytwoish/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fortytwoish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davor Babić
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- ".gitignore"
|
77
77
|
- ".rspec"
|
78
78
|
- ".travis.yml"
|
79
|
+
- CHANGELOG.md
|
79
80
|
- Gemfile
|
80
81
|
- LICENSE.txt
|
81
82
|
- README.md
|
@@ -85,7 +86,6 @@ files:
|
|
85
86
|
- fortytwoish.gemspec
|
86
87
|
- lib/fortytwoish.rb
|
87
88
|
- lib/fortytwoish/client.rb
|
88
|
-
- lib/fortytwoish/configuration.rb
|
89
89
|
- lib/fortytwoish/version.rb
|
90
90
|
homepage: https://github.com/rushplay/fortytwoish
|
91
91
|
licenses:
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Fortytwoish
|
2
|
-
ALLOWED_ENCODINGS = [
|
3
|
-
GSM7 = 'GSM7',
|
4
|
-
UCS2 = 'UCS2',
|
5
|
-
BINARY = 'BINARY'
|
6
|
-
]
|
7
|
-
|
8
|
-
class Configuration
|
9
|
-
attr_accessor :token
|
10
|
-
attr_reader :encoding
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
self.encoding = GSM7
|
14
|
-
end
|
15
|
-
|
16
|
-
def encoding=(new_encoding)
|
17
|
-
return unless ALLOWED_ENCODINGS.include?(new_encoding)
|
18
|
-
@encoding = new_encoding
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|