ongair_ruby 0.0.12

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f9ad1fd414ce09dcd2c862aac5af857bbffd04f5
4
+ data.tar.gz: f93c6da90e22dc647a4151a254355bd7c23c5c42
5
+ SHA512:
6
+ metadata.gz: 86accfce8ff23ec9b67c9c7a95b19baf33c90af54954f3c76d25f42ae3d637702a808efb5cad4d9b0f98c71bf0f8e033cc81814acca9e83dcff2f0a3df5aa485
7
+ data.tar.gz: b96ebbdcbc2f1851405bb2b649a5b1114ca07254281bf99755c29d630961b374934a7c2e7fee4f099f5170738ec50f11b7e4bfdf4e1830d5a5b64754bb1eb279
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ongair_ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 muaad
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # OngairRuby
2
+
3
+ Ruby gem for using Ongair to to interact with WhatsApp; send messages, send media, add contacts, create groups, create lists, send broadcasts and many more.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ongair_ruby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ongair_ruby
18
+
19
+ Get the Ongair API key by signing up here: http://app.ongair.im
20
+
21
+ ## Usage
22
+
23
+ client = OngairRuby::ClientV2.new("YOUR_ONGAIR_API_KEY")
24
+ # Add a contact
25
+ client.create_contact("Name of contact", "254711223344")
26
+
27
+ # Send a message
28
+ client.send_message("254711223344", "Hello")
29
+
30
+ # Send an image
31
+ client.send_image("254722123456", "http://domain.com/image.jpg")
32
+
33
+ ## Coming soon
34
+ # List of contacts
35
+ client.contacts
36
+
37
+ # Create a WhatsApp group
38
+ client.create_group("group_name", "group_type", "group_jid")
39
+
40
+ # List of groups
41
+ client.groups
42
+
43
+ # Create a distribution list
44
+ client.create_list("list_name", "list_description")
45
+
46
+ # List of distribution lists
47
+ client.lists
48
+
49
+ # Add contact to a distribution list
50
+ client.add_list_member(list_id, contact_id)
51
+
52
+ # List of distribution list members
53
+ client.list_members(list_id)
54
+
55
+ # remove contact from a distribution list
56
+ client.remove_list_member(list_id, contact_id)
57
+
58
+ # send broadcasts to a distribution list
59
+ client.send_broadcast(list_id, "Hello everyone")
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it ( https://github.com/[my-github-username]/ongair_ruby/fork )
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,64 @@
1
+ require "ongair_ruby/version"
2
+ require "httparty"
3
+
4
+ module OngairRuby
5
+ ONGAIR_URL = 'https://ongair.im'
6
+
7
+ class ClientV1
8
+ def initialize token, base_url='https://ongair.im'
9
+ @token = token
10
+ @base_url = base_url
11
+ end
12
+
13
+ def send_text_message(phone_number, message, thread=true, external_id=nil)
14
+ response = HTTParty.post("#{@base_url}/api/v1/base/send", body: {token: @token, phone_number: phone_number, text: message, thread: thread, external_id: external_id })
15
+ end
16
+
17
+ def send_image(phone_number, image_url, name, caption="", content_type='image/jpg', thread=true, external_id=nil)
18
+ response = HTTParty.post("#{@base_url}/api/v1/base/send_image", body: {token: @token, phone_number: phone_number, image: image_url, name: name, caption: caption, content_type: content_type, thread: thread, external_id: external_id })
19
+ end
20
+
21
+ def send_video(external_id, video_url, caption, thread=true)
22
+ response = HTTParty.post("#{@base_url}/api/v1/base/send_video", body: {token: @token, external_id: external_id, video_url: video_url, caption: caption, thread: thread})
23
+ end
24
+
25
+ def send_audio(external_id, audio_url, caption, thread=true)
26
+ response = HTTParty.post("#{@base_url}/api/v1/base/send_audio", body: {token: @token, external_id: external_id, audio_url: audio_url, caption: caption, thread: thread})
27
+ end
28
+ end
29
+
30
+ class ClientV2
31
+ def initialize token, base_url='https://ongair.im'
32
+ @token = token
33
+ @base_url = base_url
34
+ end
35
+
36
+ def send_message(external_id, message, options=nil, thread=true)
37
+ HTTParty.post("#{@base_url}/api/v1/base/send", body: {token: @token, external_id: external_id, text: message, thread: thread, options: options })
38
+ end
39
+
40
+ def send_image(external_id, image_url, content_type, caption=nil, options=nil, thread=true)
41
+ HTTParty.post("#{@base_url}/api/v1/base/send_image", body: {token: @token, external_id: external_id, caption: caption, image: image_url, thread: thread, options: options })
42
+ end
43
+
44
+ ##
45
+ # Send a chain of messages including options
46
+ #
47
+ # @example
48
+ #
49
+ # messages=[{ text: 'Hi'}, { text: 'Question?', options: ["1,2"]} ]
50
+ def send_chain(external_id, messages, thread=true)
51
+ HTTParty.post("#{@base_url}/api/v1/base/send_chain", body: {token: @token, external_id: external_id, messages: messages, thread: thread })
52
+ end
53
+
54
+ def send_telephone_prompt(external_id, text, thread=true)
55
+ HTTParty.post("#{@base_url}/api/v1/base/send_telephone_prompt", body: {token: @token, external_id: external_id, text: text, thread: thread })
56
+ end
57
+
58
+ def send_location_prompt(external_id, text, thread=true)
59
+ HTTParty.post("#{@base_url}/api/v1/base/send_location_prompt", body: {token: @token, external_id: external_id, text: text, thread: thread })
60
+ end
61
+
62
+
63
+ end
64
+ end
@@ -0,0 +1,3 @@
1
+ module OngairRuby
2
+ VERSION = "0.0.12"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ongair_ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ongair_ruby"
8
+ spec.version = OngairRuby::VERSION
9
+ spec.authors = ["Ongair Limited"]
10
+ spec.email = ["hello@ongair.im"]
11
+ spec.summary = %q{Ruby gem for Ongair.}
12
+ spec.description = %q{Lets you use the Ongair API to interact with Messaging services like WhatsApp, WeChat and so on.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "httparty"
22
+ spec.add_development_dependency "rspec"
23
+ spec.add_development_dependency "webmock"
24
+ spec.add_development_dependency "simplecov"
25
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe OngairRuby::ClientV1 do
4
+
5
+ context 'Sending of messages' do
6
+ subject {
7
+ OngairRuby::ClientV1.new("auth_token")
8
+ }
9
+
10
+ it 'can send text messages' do
11
+ stub = stub_request(:post, "#{OngairRuby::ONGAIR_URL}/api/v1/base/send")
12
+ .with(body: "token=auth_token&phone_number=1&text=Hi&thread=true&external_id=1")
13
+ .to_return(status: 200, :body => {sent: true, id: 1}.to_json)
14
+
15
+ response = subject.send_text_message('1', 'Hi', true, '1')
16
+ result = JSON.parse(response.body)
17
+
18
+ expect(result['sent']).to be true
19
+ expect(result['id']).to eql(1)
20
+ end
21
+
22
+ it 'can send images' do
23
+ stub = stub_request(:post, "#{OngairRuby::ONGAIR_URL}/api/v1/base/send_image")
24
+ .to_return(status: 200, :body => {sent: true, id: 1}.to_json)
25
+
26
+ response = subject.send_image('1', 'https://google.com/1.jpg', '1.jpg', 'Testing', 'image/jpg', true, '1')
27
+ result = JSON.parse(response.body)
28
+
29
+ expect(result['sent']).to be true
30
+ expect(result['id']).to eql(1)
31
+ end
32
+
33
+ it 'can send video' do
34
+ stub = stub_request(:post, "#{OngairRuby::ONGAIR_URL}/api/v1/base/send_video")
35
+ .to_return(status: 200, :body => {sent: true, id: 1}.to_json)
36
+
37
+ response = subject.send_video('1', 'https://google.com/1.avi', 'Testing',true)
38
+ result = JSON.parse(response.body)
39
+
40
+ expect(result['sent']).to be true
41
+ expect(result['id']).to eql(1)
42
+ end
43
+
44
+ it 'can send audio' do
45
+ stub = stub_request(:post, "#{OngairRuby::ONGAIR_URL}/api/v1/base/send_audio")
46
+ .to_return(status: 200, :body => {sent: true, id: 1}.to_json)
47
+
48
+ response = subject.send_audio('1', 'https://google.com/1.avi', 'Testing',true)
49
+ result = JSON.parse(response.body)
50
+
51
+ expect(result['sent']).to be true
52
+ expect(result['id']).to eql(1)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+
3
+ describe OngairRuby::ClientV2 do
4
+
5
+ context 'Sending of messages' do
6
+ subject {
7
+ OngairRuby::ClientV2.new("auth_token")
8
+ }
9
+
10
+ it 'Can send a message' do
11
+ stub = stub_request(:post, "#{OngairRuby::ONGAIR_URL}/api/v1/base/send")
12
+ .with(
13
+ body: "token=auth_token&external_id=1&text=Hello&thread=true&options=1%2C2"
14
+ )
15
+ .to_return(status: 200, :body => {sent: true, id: 1}.to_json)
16
+
17
+ response = subject.send_message('1', 'Hello', "1,2", true)
18
+ result = JSON.parse(response.body)
19
+
20
+ expect(result['sent']).to be true
21
+ expect(result['id']).to eql(1)
22
+ end
23
+
24
+ it 'Can send an image' do
25
+ stub = stub_request(:post, "#{OngairRuby::ONGAIR_URL}/api/v1/base/send_image")
26
+ .with(
27
+ body: "token=auth_token&external_id=1&caption=Hi&image=https%3A%2F%2Fimage.jpg&thread=true&options=1%2C2",
28
+ headers: {
29
+ 'Accept'=>'*/*',
30
+ })
31
+ .to_return(status: 200, :body => {sent: true, id: 1}.to_json)
32
+
33
+ response = subject.send_image('1', 'https://image.jpg', 'image/jpeg', 'Hi', "1,2", true)
34
+ result = JSON.parse(response.body)
35
+
36
+ expect(stub).to have_been_made
37
+ expect(result['sent']).to be true
38
+ expect(result['id']).to eql(1)
39
+ end
40
+
41
+ it 'can send a chain with options' do
42
+
43
+ stub = stub_request(:post, "#{OngairRuby::ONGAIR_URL}/api/v1/base/send_chain")
44
+ .to_return(status: 200, :body => {sent: true, id: 1}.to_json)
45
+
46
+ response = subject.send_chain('1', [{ :text => "Hi"}, { :text => "You good?", :options => ["Yes", "No" ]}])
47
+ result = JSON.parse(response.body)
48
+
49
+ expect(stub).to have_been_made
50
+ expect(result['sent']).to be true
51
+ expect(result['id']).to eql(1)
52
+ end
53
+
54
+ it 'can send a telephone number prompt' do
55
+ stub = stub_request(:post, "#{OngairRuby::ONGAIR_URL}/api/v1/base/send_telephone_prompt")
56
+ .with(
57
+ body: "token=auth_token&external_id=1&text=Hi&thread=true"
58
+ )
59
+ .to_return(status: 200, :body => {sent: true, id: 1}.to_json)
60
+
61
+
62
+ response = subject.send_telephone_prompt('1', "Hi")
63
+ result = JSON.parse(response.body)
64
+
65
+ expect(stub).to have_been_made
66
+ expect(result['sent']).to be true
67
+ expect(result['id']).to eql(1)
68
+ end
69
+
70
+ it 'can send a location prompt' do
71
+ stub = stub_request(:post, "#{OngairRuby::ONGAIR_URL}/api/v1/base/send_location_prompt")
72
+ .with(
73
+ body: "token=auth_token&external_id=1&text=Hi&thread=true"
74
+ )
75
+ .to_return(status: 200, :body => {sent: true, id: 1}.to_json)
76
+
77
+ response = subject.send_location_prompt('1', "Hi")
78
+ result = JSON.parse(response.body)
79
+
80
+ expect(stub).to have_been_made
81
+ expect(result['sent']).to be true
82
+ expect(result['id']).to eql(1)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,14 @@
1
+ require 'webmock/rspec'
2
+ require 'rspec'
3
+ require 'ongair_ruby'
4
+
5
+ WebMock.disable_net_connect!
6
+ RSpec.configure do |config|
7
+ config.expect_with :rspec do |expectations|
8
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
9
+ end
10
+
11
+ config.mock_with :rspec do |mocks|
12
+ mocks.verify_partial_doubles = true
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ongair_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.12
5
+ platform: ruby
6
+ authors:
7
+ - Ongair Limited
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Lets you use the Ongair API to interact with Messaging services like
70
+ WhatsApp, WeChat and so on.
71
+ email:
72
+ - hello@ongair.im
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/ongair_ruby.rb
84
+ - lib/ongair_ruby/version.rb
85
+ - ongair_ruby.gemspec
86
+ - spec/client_v1_spec.rb
87
+ - spec/client_v2_spec.rb
88
+ - spec/spec_helper.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.6.11
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Ruby gem for Ongair.
113
+ test_files:
114
+ - spec/client_v1_spec.rb
115
+ - spec/client_v2_spec.rb
116
+ - spec/spec_helper.rb