easy-sms 0.9.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6a555985287091ddf1af312e45dccd6a25ffedc
4
+ data.tar.gz: f22c228e114a89a1fc9caf2e7e1a5a01b70b7838
5
+ SHA512:
6
+ metadata.gz: 555fd5d9c0e3b707dfd9c8169fe4c26601c45387da1680592efd82f790d892ffc5017684470cdd1016536c42fafc21e9cf6ff8fd719d01e995e213cf5a0f3bc6
7
+ data.tar.gz: f318ac47eb847159ddf3b53cb8eebad8e047f892b1923a0a9955e287b2e72f310de4d3cabf0bc112a3dfc7efa7af1f97460b1ea47a37db0fa2408a97605fd309
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at paveltyk@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in easy-sms.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 PavelT
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,105 @@
1
+ # Easy::Sms
2
+
3
+ The Easy SMS gem is a wrapper for Easy SMS API.
4
+
5
+ ## Using with Ruby/Rails
6
+
7
+ First of all you will need to install the easy-sms gem. And add it to a Gemfile if needed.
8
+
9
+ ```
10
+ $ gem install easy-sms
11
+ ```
12
+
13
+ ### Sending SMS
14
+
15
+ You can send SMS right away with the `ENV['EASYSMS_URL']` and 'easy-sms' gem installed in your app. No additional configuration required.
16
+
17
+ Use `EasySMS::Client#messages.create(options)` to send SMS. Options:
18
+
19
+ * `to` - required. Recipient phone number in [E.164](http://en.wikipedia.org/wiki/E.164) format. Example: '+12067450316'
20
+ * `from` - optional. Sender phone number in [E.164](http://en.wikipedia.org/wiki/E.164) format. Example: '+12067450316'
21
+ * `body` - required. The text body of the message. Up to 1600 characters long.
22
+
23
+ ```ruby
24
+ require 'easy-sms'
25
+
26
+ # By default initializer will use the EASYSMS_URL config variable to configure the client instance.
27
+ client = EasySMS::Client.new
28
+ puts client.messages.create to: '+12067450316', body: 'Hello from Easy SMS.' #=> {"body"=>"Hello from Easy SMS.", "c_at"=>2016-01-25 13:58:38 UTC, "from"=>nil, "status"=>"pending", "to"=>"+12067450316", "uid"=>"56a62a0ebbf109000c000000"}
29
+ # The received SMS can be seen at: http://sms-receive.net/12067450316-USA (free web service to receive SMS online)
30
+ ```
31
+
32
+ Note the status of SMS is 'pending', which mean the SMS is not delivered yet. It will take a few seconds to process the SMS. You may receive HTTP POST requests to the status callback URL once SMS delivery status change. To do so, please specify the `sms_status_url` for your account. [Read more](#configuring-easy-sms-account)
33
+
34
+ ### Creating and releasing phone numbers
35
+
36
+ Use `EasySMS::Client#phone_numbers.create(options)` to create a phone number. Options:
37
+
38
+ * `country_code` - optional. Two-letter country code of the phone number. Default 'US'
39
+ * `pattern` - optional. The pattern of the phone number. Default is nil. Example: '*******654'
40
+ * `inbound_sms_url` - optional. The callback URL to be triggered when your phone number receives SMS. Example: 'http://api.example.com/sms/callback'
41
+
42
+ ```ruby
43
+ require 'easy-sms'
44
+
45
+ client = EasySMS::Client.new
46
+ phone_number = client.phone_numbers.create #=> {"inbound_sms_url"=>nil, "phone_number"=>"+12183011654", "primary"=>true, "uid"=>"56a630d53017290006000000", "country_code"=>"US"}
47
+ puts "Purchased phone number #{phone_number['phone_number']}"
48
+ client.phone_numbers.delete(phone_number['uid'])
49
+ puts "Released phone number #{phone_number['phone_number']}"
50
+ ```
51
+
52
+ The `EasySMS::Client#phone_numbers.delete(uid)` method is used to release a phone number. This method accepts one argument - phone number UID *(the one returned by EasySMS::Client#phone_numbers.create)*.
53
+
54
+ ### Receiving SMS
55
+
56
+ Any inbound SMS to one of your phone numbers will trigger a HTTP POST request to your callback URL. You may set the callback url on the phone number instance via the `EasySMS::Client#phone_numbers.update` method, or pass the `inbound_sms_url` option to `EasySMS::Client#phone_numbers.create` when you create a phone number.
57
+
58
+ `EasySMS::Client#phone_numbers.update(uid, options)` accepts phone number UID and options:
59
+
60
+ * `inbound_sms_url` - optional. The callback URL to be triggered when your phone number receives SMS. Example: 'http://api.example.com/sms/callback'
61
+
62
+ ```ruby
63
+ require 'easy-sms'
64
+
65
+ client = EasySMS::Client.new
66
+ phone_numbers = client.phone_numbers.list
67
+ uid = phone_numbers.list.first['uid']
68
+ client.phone_numbers.update(uid, inbound_sms_url: 'http://api.example.com/sms/callback') #=> {message_uid: '56a21298778404d264000000', to: '+12183011654', from: '+12183011699', body: 'Hello there!', direction: 'inbound', c_at: '2016-01-22 14:53:04 UTC'}
69
+ ```
70
+
71
+ The POST request to your callback URL will include these parameters:
72
+
73
+ * `message_uid` - UID of the message. A 24 characters string.
74
+ * `to` - recipient phone number (one of your phone numbers) in [E.164](http://en.wikipedia.org/wiki/E.164) format. Example: '+12067450316'
75
+ * `from` - sender phone number in [E.164](http://en.wikipedia.org/wiki/E.164) format. Example: '+12067450399'
76
+ * `body` - text body of SMS.
77
+ * `direction` - 'inbound'.
78
+ * `c_at` - time when SMS was received. Example: '2016-01-22 14:53:04 UTC'
79
+
80
+ ### Configuring Easy SMS Account
81
+
82
+ You may want to fine tune your account. To check current account state run `EasySMS::client.account.get`. The result is a hash with valuable information for current account status and configuration.
83
+
84
+ Use `EasySMS::client.account.update(options)` to update your account configuration. Options:
85
+
86
+ * `sms_status_url` - optional. The callback URL to be triggered when SMS status change. Example: ‘http://api.example.com/sms-status/callback’
87
+
88
+ ```ruby
89
+ client = EasySMS::Client.new
90
+ client.account.get #=> {"plan"=>"gold", "sms_status_url"=>nil, "uid"=>"56a21186778404d266000001"}
91
+ client.account.update(sms_status_url: 'http://api.example.com/sms-status/callback') #=> {"plan"=>"gold", "sms_status_url"=>"http://api.example.com/sms-status/callback", "uid"=>"56a21186778404d266000001"}
92
+ ```
93
+
94
+ ## Local Setup
95
+
96
+ After provisioning the add-on it’s necessary to locally replicate the config vars so your development environment can operate against the service.
97
+
98
+ Use the **Foreman** gem for example to run a commands within environment loaded from `.env` file. Add the `EASYSMS_URL` variable to your `.env` file.
99
+
100
+ ```
101
+ EASYSMS_URL=https://<account_id>:<token>@api.easysmsapp.com/accounts/<account_id>
102
+ ```
103
+
104
+ Though less portable it’s also possible to run a script using `export EASYSMS_URL=https://<account_id>:<token>@api.easysmsapp.com/accounts/<account_id> ruby script.rb`.
105
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "easy_sms"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'easy_sms/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "easy-sms"
8
+ spec.version = EasySMS::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ["PavelT"]
11
+ spec.email = ["paveltyk@gmail.com"]
12
+
13
+
14
+ spec.summary = %q{Easy SMS API wrapper}
15
+ spec.description = %q{Send SMS globally with Easy SMS gem. Ruby API wrapper}
16
+ spec.homepage = "https://github.com/PavelTyk/easy-sms"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "webmock", "~> 1.22"
26
+
27
+ spec.add_dependency 'rest-client', '~> 1.8'
28
+ spec.add_dependency 'json', '~> 1.8'
29
+ end
@@ -0,0 +1 @@
1
+ require 'easy_sms'
@@ -0,0 +1,12 @@
1
+ require 'time'
2
+ require 'json'
3
+ require 'rest-client'
4
+
5
+ require "easy_sms/version"
6
+ require "easy_sms/client"
7
+ require "easy_sms/account_resource"
8
+ require "easy_sms/message_resource"
9
+ require "easy_sms/phone_number_resource"
10
+
11
+ module EasySMS
12
+ end
@@ -0,0 +1,17 @@
1
+ module EasySMS
2
+ class AccountResource < Struct.new(:client)
3
+ def get
4
+ res = client.get('', {})
5
+
6
+ JSON.parse(res).tap do |json|
7
+ json['c_at'] = Time.parse(json['c_at']) if json['c_at']
8
+ end
9
+ end
10
+
11
+ def update(attrs = {})
12
+ res = client.put('', attrs)
13
+
14
+ JSON.parse(res)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,61 @@
1
+ module EasySMS
2
+ class Client
3
+ attr_reader :uri
4
+
5
+ def initialize(url = nil)
6
+ @url = url || ENV['EASYSMS_URL'] || ENV['EASY_SMS_URL']
7
+ raise 'Resource URL not set. Please pass a valid URL to initializer, or set EASYSMS_URL environment variable.' unless @url
8
+ @resource = RestClient::Resource.new(@url)
9
+ @uri = URI.parse(@url)
10
+ end
11
+
12
+ def messages
13
+ MessageResource.new(self)
14
+ end
15
+
16
+ def phone_numbers
17
+ PhoneNumberResource.new(self)
18
+ end
19
+
20
+ def account
21
+ AccountResource.new(self)
22
+ end
23
+
24
+ def get(path, attrs)
25
+ begin
26
+ #TODO: add attrs to url or let it be handled by RestClient
27
+ @resource[path].get(content_type: :json, accept: :json)
28
+ rescue RestClient::Exception => e
29
+ json = JSON.parse(e.response) rescue nil
30
+ raise Error.new([e, json].compact.join(' '))
31
+ end
32
+ end
33
+
34
+ def post(path, attrs)
35
+ begin
36
+ @resource[path].post(attrs.to_json, content_type: :json, accept: :json)
37
+ rescue RestClient::Exception => e
38
+ json = JSON.parse(e.response) rescue nil
39
+ raise Error.new([e, json].compact.join(' '))
40
+ end
41
+ end
42
+
43
+ def put(path, attrs)
44
+ begin
45
+ @resource[path].put(attrs.to_json, content_type: :json, accept: :json)
46
+ rescue RestClient::Exception => e
47
+ json = JSON.parse(e.response) rescue nil
48
+ raise Error.new([e, json].compact.join(' '))
49
+ end
50
+ end
51
+
52
+ def delete(path)
53
+ begin
54
+ @resource[path].delete(content_type: :json, accept: :json)
55
+ rescue RestClient::Exception => e
56
+ json = JSON.parse(e.response) rescue nil
57
+ raise Error.new([e, json].compact.join(' '))
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,11 @@
1
+ module EasySMS
2
+ class MessageResource < Struct.new(:client)
3
+ def create(attrs = {})
4
+ res = client.post('/messages', attrs)
5
+
6
+ JSON.parse(res).tap do |json|
7
+ json['c_at'] = Time.parse(json['c_at']) if json['c_at']
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module EasySMS
2
+ class PhoneNumberResource < Struct.new(:client)
3
+ def list(attrs = {})
4
+ res = client.get('/phone_numbers', attrs)
5
+
6
+ JSON.parse(res)
7
+ end
8
+
9
+ def create(attrs = {})
10
+ res = client.post('/phone_numbers', attrs)
11
+
12
+ JSON.parse(res)
13
+ end
14
+
15
+ def update(uid, attrs = {})
16
+ res = client.put("/phone_numbers/#{uid}", attrs)
17
+
18
+ JSON.parse(res)
19
+ end
20
+
21
+ def delete(uid)
22
+ res = client.delete("/phone_numbers/#{uid}")
23
+
24
+ JSON.parse(res)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module EasySMS
2
+ VERSION = '0.9.0'
3
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy-sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - PavelT
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.22'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.22'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.8'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.8'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.8'
97
+ description: Send SMS globally with Easy SMS gem. Ruby API wrapper
98
+ email:
99
+ - paveltyk@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - easy-sms.gemspec
115
+ - lib/easy-sms.rb
116
+ - lib/easy_sms.rb
117
+ - lib/easy_sms/account_resource.rb
118
+ - lib/easy_sms/client.rb
119
+ - lib/easy_sms/message_resource.rb
120
+ - lib/easy_sms/phone_number_resource.rb
121
+ - lib/easy_sms/version.rb
122
+ homepage: https://github.com/PavelTyk/easy-sms
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Easy SMS API wrapper
146
+ test_files: []