ongair 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d8c1550c88a7bccc1428d0f8e83a8d8fa111bb0
4
+ data.tar.gz: 82b9326ceca5d9230c338f8f2e6df72ae7c59e39
5
+ SHA512:
6
+ metadata.gz: 073cf0b3cd6cf9f0c128e86780bcf59ef17cc6f8ab4f2e088bb95c5bb4dd29cf2802724ce713ed5fd8f35918531db766cca462ce60006f077789f57b70bd928b
7
+ data.tar.gz: 74e4cfcc5788421caaf69f2ce92628e39b2a790693b2f7defa1be2fe859e12cc302e7e77ceb59ea19613473e503ca2f163a168e519c5e93bbc69a21c2c3ab42b
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 documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ongair.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Ongair API wrapper
2
+
3
+ A ruby wrapper for the [ongair.im](http://ongair.im) API that allows you to send and receive chat messages.
4
+ Currently ongair supports whatsapp and wechat.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ongair'
12
+ ```
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install ongair
17
+
18
+ ## Usage
19
+
20
+ ```ruby
21
+
22
+ # configure your API token
23
+ Ongair.configure do |c|
24
+ c.token = ''
25
+ end
26
+
27
+ # receiving messages:
28
+ message = Ongair::Message.new(params) # simply initialize a new message with the params from the ongair webhook
29
+ message.type.image?
30
+ message.text
31
+ message.image
32
+ # see lib/ongair/message.rb for details
33
+
34
+ # sending messages (currently text and images are supported)
35
+ message = Ongair::Message.new(phone_number: 'number', text: 'hello world') # initialize a new message with the params described in the ongair API
36
+ message.deliver! # or message.deliver_to('4912345678')
37
+
38
+ ```
39
+
40
+ ## ToDo:
41
+
42
+ * support for more ongair message endpoints
43
+ * support for handling contacts
44
+ * support for groups
45
+ * sending broadcasts
46
+ * support for message receipts
47
+
48
+ Want to help? :green_heart:
49
+
50
+ ------------
51
+
52
+ Built with love by [@njirap](https://twitter.com/njirap) and [@bumi](https://twitter.com/bumi) in Nairobi and released under the MIT-Licence.
53
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ongair"
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
data/lib/ongair.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "ongair/version"
2
+
3
+ require 'active_support/configurable'
4
+ require 'rest-client'
5
+
6
+ require 'ongair/message'
7
+ require 'ongair/request'
8
+ module Ongair
9
+ include ActiveSupport::Configurable
10
+
11
+ end
12
+ Ongair.configure do |c|
13
+ c.base_url = 'https://app.ongair.im/api/v1/base'
14
+ end
@@ -0,0 +1,40 @@
1
+ require 'active_support/string_inquirer'
2
+ require 'virtus'
3
+ module Ongair
4
+ class Message
5
+ include Virtus.model
6
+ attribute :name, String
7
+ attribute :id, String
8
+ attribute :name, String
9
+ attribute :profile_pic, String
10
+ attribute :notification_type, String, default: 'Message'
11
+ attribute :text, String
12
+ attribute :image, String
13
+ attribute :account, String
14
+ attribute :phone_number, String
15
+ attribute :caption, String
16
+ attribute :sent, Boolean
17
+ attribute :thread, Boolean
18
+
19
+ def type
20
+ ActiveSupport::StringInquirer.new self.notification_type.to_s.sub('Received', '').downcase
21
+ end
22
+
23
+ def type=(value)
24
+ self.notification_type = "#{value.to_s.capitalize}Received"
25
+ end
26
+
27
+ def deliver_to(phone_number)
28
+ response = Ongair::Request.new(self).deliver_to(phone_number)
29
+ self.id = response['id']
30
+ self.sent = response['sent']
31
+ end
32
+
33
+ def deliver!
34
+ response = Ongair::Request.new(self).deliver!
35
+ self.id = response['id']
36
+ self.sent = response['sent']
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,36 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+ module Ongair
4
+
5
+ class Request
6
+ attr_reader :message
7
+
8
+ ENDPOINTS = {
9
+ 'message' => '/send',
10
+ 'image' => '/send_image'
11
+ }
12
+ ENDPOINTS.default = '/send'
13
+
14
+ def initialize(message)
15
+ @message = message
16
+ end
17
+
18
+ def deliver!
19
+ JSON.parse RestClient.post self.url, self.message.attributes, self.headers
20
+ end
21
+
22
+ def deliver_to(phone_number)
23
+ params = self.message.attributes.merge(phone_number: phone_number)
24
+ JSON.parse RestClient.post self.url, params, self.headers
25
+ end
26
+
27
+ def headers
28
+ {'Accept' => 'application/json', 'Authorization' => "Token token=#{Ongair.config.token}"}
29
+ end
30
+
31
+ def url
32
+ Ongair.config.base_url + ENDPOINTS[self.message.type]
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Ongair
2
+ VERSION = "0.1.0"
3
+ end
data/ongair.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ongair/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ongair"
8
+ spec.version = Ongair::VERSION
9
+ spec.authors = ["Michael Bumann", "Njirap"]
10
+ spec.email = ["michael@railslove.com", "njirap@gmail.com"]
11
+
12
+ spec.summary = %q{simple API wrapper around the ongair.im API}
13
+ spec.description = %q{This API wrapper allows you to interact with the ongair.im API to receive and to send messages. (currently whatsapp only)}
14
+ spec.homepage = "http://michaelbumann.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_dependency "activesupport", ">= 3.0"
25
+ spec.add_dependency "virtus", "~> 1.0.0"
26
+ spec.add_dependency "rest-client", "~> 1.8.0"
27
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ongair
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bumann
8
+ - Njirap
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-10-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.8'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.8'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: activesupport
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: virtus
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.0
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.0
70
+ - !ruby/object:Gem::Dependency
71
+ name: rest-client
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 1.8.0
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 1.8.0
84
+ description: This API wrapper allows you to interact with the ongair.im API to receive
85
+ and to send messages. (currently whatsapp only)
86
+ email:
87
+ - michael@railslove.com
88
+ - njirap@gmail.com
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - ".travis.yml"
96
+ - Gemfile
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/ongair.rb
102
+ - lib/ongair/message.rb
103
+ - lib/ongair/request.rb
104
+ - lib/ongair/version.rb
105
+ - ongair.gemspec
106
+ homepage: http://michaelbumann.com
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: simple API wrapper around the ongair.im API
130
+ test_files: []