sendblue 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f5cbbb07bc00a32906da9255ef3069a9fa8b1443a88c841cb3e9d77d8dbd88fc
4
+ data.tar.gz: 72225807960cd643727ba3783b168d37921d7194b369efc756063d485e03132d
5
+ SHA512:
6
+ metadata.gz: 5ea19290f8de56baac1aacbba805520b4d4d0eeed54d33eec82e49b2a44b39e4f63f67a5c38c553c607c695eb2a68a393821074a5c4d4353e412170c459782e1
7
+ data.tar.gz: bc918816a325a55a7704a63179bf0e4064a0a2c4c6de8cc75eca1179fec4070ff0a8bdbf2ca197fe0a4dc2fc465ba922208e6f02fb418564344595789d5dda7b
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake" /></Settings>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in sendblue.gemspec
6
+ gemspec
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sendblue (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
+ crack (0.4.3)
12
+ safe_yaml (~> 1.0.0)
13
+ diff-lcs (1.4.4)
14
+ hashdiff (1.0.1)
15
+ public_suffix (4.0.5)
16
+ rake (13.0.1)
17
+ rspec (3.9.0)
18
+ rspec-core (~> 3.9.0)
19
+ rspec-expectations (~> 3.9.0)
20
+ rspec-mocks (~> 3.9.0)
21
+ rspec-core (3.9.2)
22
+ rspec-support (~> 3.9.3)
23
+ rspec-expectations (3.9.2)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.9.0)
26
+ rspec-mocks (3.9.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.9.0)
29
+ rspec-support (3.9.3)
30
+ safe_yaml (1.0.5)
31
+ vcr (6.0.0)
32
+ webmock (3.8.3)
33
+ addressable (>= 2.3.6)
34
+ crack (>= 0.3.2)
35
+ hashdiff (>= 0.4.0, < 2.0.0)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (~> 1.17)
42
+ rake (~> 13)
43
+ rspec (~> 3.0)
44
+ sendblue!
45
+ vcr (~> 6.0)
46
+ webmock (~> 3.8)
47
+
48
+ BUNDLED WITH
49
+ 1.17.2
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2020 Jim Jones
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Sendblue
2
+
3
+ This is a client library for the [SendBlue](https://sendblue.co/) message service.
4
+
5
+ [SendBlue](https://sendblue.co/) allows you to send iMessages programmatically. The messages received show up blue as if they were sent from an iPhone.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sendblue'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sendblue
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ # Look up your API key/secret
27
+ # https://sendblue.co/account
28
+
29
+ client = Sendblue::Sendblue.new(<key>, <secret>)
30
+
31
+ message = client.send_message(<phone number>, <message>)
32
+ status = client.message_status(message.message_handle)
33
+ ```
34
+
35
+ ## Running the Tests
36
+ ```
37
+ rspec spec/sendblue_spec.rb
38
+ ```
@@ -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 "sendblue"
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(__FILE__)
@@ -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,2 @@
1
+ require "sendblue/version"
2
+ require "sendblue/sendblue"
@@ -0,0 +1,67 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
4
+ require 'json'
5
+ require 'ostruct'
6
+
7
+ module Sendblue
8
+ class MessageNotFoundException < StandardError; end
9
+ class GeneralException < StandardError; end
10
+
11
+ class Sendblue
12
+ attr_reader :key, :secret
13
+
14
+ def initialize(key, secret)
15
+ @key = key
16
+ @secret = secret
17
+ end
18
+
19
+ def send_message(phone_number, content)
20
+ response = request("https://api.sendblue.co/api/send-message",
21
+ method: :Post,
22
+ params: {number: phone_number, content: content})
23
+
24
+ body = response.read_body
25
+
26
+ if response.is_a?(Net::HTTPSuccess)
27
+ return OpenStruct.new(JSON.parse(body))
28
+ end
29
+
30
+ raise ::Sendblue::GeneralException.new(body)
31
+ end
32
+
33
+ def message_status(message_handle)
34
+ response = request("https://api.sendblue.co/api/status?handle=#{CGI::escape(message_handle)}")
35
+ body = response.read_body
36
+
37
+ if response.is_a?(Net::HTTPSuccess)
38
+ return OpenStruct.new(JSON.parse(body))
39
+ elsif response.is_a?(Net::HTTPNotFound)
40
+ raise ::Sendblue::MessageNotFoundException.new("Could not find message handle #{message_handle}")
41
+ end
42
+
43
+ raise ::Sendblue::GeneralException.new(body)
44
+ end
45
+
46
+ def request(url, method: :Get, params: {})
47
+ url = URI(url)
48
+
49
+ http = Net::HTTP.new(url.host, url.port)
50
+ http.use_ssl = true
51
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
52
+
53
+ klass = Object.const_get("Net::HTTP::#{method}")
54
+ request = klass.new(url)
55
+
56
+ request["sb-api-key-id"] = @key
57
+ request["sb-api-secret-key"] = @secret
58
+
59
+ request["content-type"] = 'application/json'
60
+ request["accept"] = 'application/json'
61
+
62
+ request.body = params.to_json unless params.empty?
63
+
64
+ http.request(request)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,3 @@
1
+ module Sendblue
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "sendblue/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sendblue"
8
+ spec.version = Sendblue::VERSION
9
+ spec.authors = ["Jim Jones"]
10
+ spec.email = ["jim.jones1@gmail.com"]
11
+
12
+ spec.summary = %q{Simple client wrapper for the SendBlue.co service.}
13
+ spec.description = %q{Allows for the sending of messages through the SendBlue service.}
14
+ spec.homepage = "https://www.github.com/aantix/sendblue"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.17"
26
+ spec.add_development_dependency "rake", "~> 13"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "vcr", "~> 6.0"
29
+ spec.add_development_dependency "webmock", "~> 3.8"
30
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sendblue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jim Jones
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-04 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.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '13'
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: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '6.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '6.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.8'
83
+ description: Allows for the sending of messages through the SendBlue service.
84
+ email:
85
+ - jim.jones1@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rakeTasks"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/sendblue.rb
102
+ - lib/sendblue/sendblue.rb
103
+ - lib/sendblue/version.rb
104
+ - sendblue.gemspec
105
+ homepage: https://www.github.com/aantix/sendblue
106
+ licenses: []
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubygems_version: 3.0.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Simple client wrapper for the SendBlue.co service.
127
+ test_files: []