coolsms-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2238ae2307f0f0c4a92b2899288c84d91607a194
4
+ data.tar.gz: 29328c3d0e31bb2d333aa0b02769db3b97651a32
5
+ SHA512:
6
+ metadata.gz: fd5a02bba4dfd6f28aea04757878b84c9a89c59a18531c9145ef05d0e282fc6346cc32a719783d3027a9fbcb439c242ff042cf3cf91e2ebc3219e65195bbc802
7
+ data.tar.gz: c4dc4c032e2eaec51e12ec3fb1a8a76e9b841d621cb83f18e50f401f5276096acbf511a45d39910ad3afe7f9810dd28c1c8b5d6828bac5583ef4d9d3498082e8
data/.gitignore ADDED
@@ -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 Fuubar
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.2.1
5
+ - 2.2.2
6
+ - 2.2.3
7
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in coolsms-client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 kenleytomlin
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.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Coolsms::Client
2
+
3
+ This is a simple client for sending SMS and LMS messages to mobile phones in South Korea via the CoolSMS api. http://www.coolsms.co.kr/
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'coolsms-client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install coolsms-client
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ client = Coolsms::Client.new :api_key => 'YOUR_API_KEY', :api_secret => 'YOUR_API_SECRET', :sender => "YOUR_NUMBER"
25
+
26
+ client.send_message :to => "RECIPIENTS_PHONE_NUMBER", :text => "hello world"
27
+ # => { :success => true, :error_count => 0, :success_count => 1, :result_message => "Success" :status_code => 200 }
28
+ ```
29
+
30
+
31
+
32
+ ## Development
33
+ Fork the repository, add a feature or bug fix branch. Submit a PR. Please include specs where necessary.
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/CosmicColor/coolsms-client.
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
43
+
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "coolsms/client"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'coolsms/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "coolsms-client"
8
+ spec.version = Coolsms::VERSION
9
+ spec.authors = ["kenleytomlin","neospecial"]
10
+ spec.email = ["kenleytomlin@gmail.com"]
11
+
12
+ spec.summary = %q{Simple client for sending sms messages via the coolsms api}
13
+ spec.description = %q{Send sms messages via the coolsms api}
14
+ spec.homepage = "https://github.com/CosmicColor/coolsms-client"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency "httparty", "~> 0.13"
31
+ spec.add_development_dependency "timecop", "~> 0.8"
32
+ spec.add_development_dependency "webmock", "~> 1.21"
33
+ spec.add_development_dependency "fuubar", "~> 2.0"
34
+ spec.add_development_dependency "bundler", "~> 1.10"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.3"
37
+ end
@@ -0,0 +1,3 @@
1
+ module Coolsms
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,52 @@
1
+ require "coolsms/client/version"
2
+ require 'httparty'
3
+ require 'json'
4
+
5
+ module Coolsms
6
+ class Client
7
+
8
+ COOLSMS_URL = "https://api.coolsms.co.kr/1/send"
9
+
10
+ def initialize(options)
11
+ raise ArgumentError.new "sender must not be nil" unless options[:sender]
12
+ raise ArgumentError.new "api_key must not be nil" unless options[:api_key]
13
+ raise ArgumentError.new "api_secret must not be nil" unless options[:api_secret]
14
+
15
+ @api_key = options[:api_key]
16
+ @api_secret = options[:api_secret]
17
+ @sender = options[:sender]
18
+ end
19
+
20
+ def send_message(options)
21
+ raise ArgumentError.new "to must not be nil" unless options[:to]
22
+ raise ArgumentError.new "text must not be nil" unless options[:text]
23
+
24
+ ts = timestamp
25
+ slt = salt
26
+ signature = signature(ts,slt)
27
+ type = options[:text].bytesize > 80 ? 'LMS' : 'SMS'
28
+ res = HTTParty.post(COOLSMS_URL, :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, :body => { :api_key => @api_key, :type => type, :salt => slt, :signature => signature, :to => options[:to], :timestamp => ts, :from => @sender, :text => options[:text] })
29
+ parse_response res
30
+ end
31
+
32
+ private
33
+
34
+ def parse_response(res)
35
+ parsed_response = JSON.parse(res.parsed_response)
36
+ { :success => res.code > 200 ? false : true, :error_count => parsed_response['error_count'], :success_count => parsed_response['success_count'], :result_message => parsed_response['result_message'], :status_code => res.code }
37
+ end
38
+
39
+ def salt
40
+ SecureRandom.hex(30)
41
+ end
42
+
43
+ def timestamp
44
+ Time.now.to_i
45
+ end
46
+
47
+ def signature(ts,slt)
48
+ digest = OpenSSL::Digest.new 'md5'
49
+ OpenSSL::HMAC.hexdigest digest, @api_secret, "#{ts}#{slt}"
50
+ end
51
+ end
52
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coolsms-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kenleytomlin
8
+ - neospecial
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-09-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.13'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.13'
28
+ - !ruby/object:Gem::Dependency
29
+ name: timecop
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0.8'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.8'
42
+ - !ruby/object:Gem::Dependency
43
+ name: webmock
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.21'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.21'
56
+ - !ruby/object:Gem::Dependency
57
+ name: fuubar
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: bundler
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.10'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.10'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rake
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '10.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '10.0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rspec
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '3.3'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '3.3'
112
+ description: Send sms messages via the coolsms api
113
+ email:
114
+ - kenleytomlin@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - coolsms-client.gemspec
129
+ - lib/coolsms/client.rb
130
+ - lib/coolsms/client/version.rb
131
+ homepage: https://github.com/CosmicColor/coolsms-client
132
+ licenses:
133
+ - MIT
134
+ metadata:
135
+ allowed_push_host: https://rubygems.org
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.4.5
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Simple client for sending sms messages via the coolsms api
156
+ test_files: []