mogreet 0.0.1 → 0.0.2.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -6
- data/Gemfile +1 -2
- data/README.md +49 -28
- data/Rakefile +8 -3
- data/lib/mogreet.rb +12 -8
- data/lib/mogreet/client.rb +60 -0
- data/lib/mogreet/deprecated.rb +56 -0
- data/lib/mogreet/keyword.rb +27 -0
- data/lib/mogreet/list.rb +67 -0
- data/lib/mogreet/media.rb +19 -0
- data/lib/mogreet/request.rb +19 -0
- data/lib/mogreet/response.rb +7 -0
- data/lib/mogreet/system.rb +10 -0
- data/lib/mogreet/transaction.rb +30 -0
- data/lib/mogreet/user.rb +33 -1
- data/lib/mogreet/version.rb +2 -2
- data/mogreet.gemspec +20 -19
- data/spec/cassettes/deprecated_mms.yml +53 -0
- data/spec/cassettes/keyword_add.yml +56 -0
- data/spec/cassettes/keyword_check.yml +57 -0
- data/spec/cassettes/keyword_list.yml +121 -0
- data/spec/cassettes/keyword_remove.yml +56 -0
- data/spec/cassettes/list_append.yml +61 -0
- data/spec/cassettes/list_create.yml +57 -0
- data/spec/cassettes/list_destroy.yml +56 -0
- data/spec/cassettes/list_download.yml +59 -0
- data/spec/cassettes/list_empty.yml +56 -0
- data/spec/cassettes/list_info.yml +65 -0
- data/spec/cassettes/list_list.yml +63 -0
- data/spec/cassettes/list_prune.yml +61 -0
- data/spec/cassettes/list_send.yml +56 -0
- data/spec/cassettes/media_destroy.yml +61 -0
- data/spec/cassettes/media_list.yml +72 -0
- data/spec/cassettes/media_upload.yml +3602 -0
- data/spec/cassettes/ping_invalid.yml +51 -0
- data/spec/cassettes/ping_success.yml +147 -0
- data/spec/cassettes/transaction_lookup.yml +74 -0
- data/spec/cassettes/transaction_send.yml +101 -0
- data/spec/cassettes/user_info_success.yml +56 -0
- data/spec/cassettes/user_lookup_success.yml +104 -0
- data/spec/cassettes/user_transactions_success.yml +62 -0
- data/spec/cassettes/user_uncache_success.yml +56 -0
- data/spec/deprecated_spec.rb +37 -0
- data/spec/fixtures/api.jpg +0 -0
- data/spec/keyword_spec.rb +84 -0
- data/spec/list_spec.rb +193 -0
- data/spec/media_spec.rb +67 -0
- data/spec/ping_spec.rb +43 -0
- data/spec/spec_helper.rb +26 -7
- data/spec/transaction_spec.rb +53 -0
- data/spec/user_spec.rb +66 -0
- metadata +93 -59
- data/.rspec +0 -1
- data/LICENSE +0 -22
- data/lib/mogreet/config.rb +0 -3
- data/lib/mogreet/message.rb +0 -8
- data/lib/mogreet/mogreet.rb +0 -13
- data/lib/mogreet/response/transaction_send.rb +0 -5
- data/spec/fixtures/transaction_send.xml +0 -6
- data/spec/mogreet/config_spec.rb +0 -17
- data/spec/mogreet/message_spec.rb +0 -32
data/.gitignore
CHANGED
@@ -1,14 +1,9 @@
|
|
1
1
|
*.gem
|
2
2
|
*.rbc
|
3
3
|
.bundle
|
4
|
-
.rvmrc
|
5
4
|
.config
|
6
|
-
.yardoc
|
7
|
-
Gemfile.lock
|
8
|
-
InstalledFiles
|
9
|
-
_yardoc
|
10
5
|
coverage
|
11
|
-
|
6
|
+
InstalledFiles
|
12
7
|
lib/bundler/man
|
13
8
|
pkg
|
14
9
|
rdoc
|
@@ -16,3 +11,8 @@ spec/reports
|
|
16
11
|
test/tmp
|
17
12
|
test/version_tmp
|
18
13
|
tmp
|
14
|
+
|
15
|
+
# YARD artifacts
|
16
|
+
.yardoc
|
17
|
+
_yardoc
|
18
|
+
doc/
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,50 @@
|
|
1
|
-
|
1
|
+
Mogreet API
|
2
|
+
===========
|
3
|
+
|
4
|
+
Examples assume that your credentials are set via config vars (https://devcenter.heroku.com/articles/config-vars).
|
5
|
+
|
6
|
+
__Ping__
|
7
|
+
|
8
|
+
client = Mogreet::Client.new(ENV['MOGREET_CLIENT_ID'], ENV['MOGREET_TOKEN'])
|
9
|
+
response = client.system.ping
|
10
|
+
puts response.message
|
11
|
+
|
12
|
+
|
13
|
+
__Send MMS to one recipient__
|
14
|
+
|
15
|
+
client = Mogreet::Client.new(ENV['MOGREET_CLIENT_ID'], ENV['MOGREET_TOKEN'])
|
16
|
+
response = client.transaction.send(
|
17
|
+
:campaign_id => ENV['MOGREET_MMS_CAMPAIGN_ID'],
|
18
|
+
:to => '1111111111',
|
19
|
+
:message => 'hello world',
|
20
|
+
:content_url => 'https://wp-uploads.mogreet.com/wp-uploads/2013/02/API-Beer-sticker-300dpi-1024x1024.jpg'
|
21
|
+
)
|
22
|
+
|
23
|
+
__Send SMS to one recipient__
|
24
|
+
|
25
|
+
client = Mogreet::Client.new(ENV['MOGREET_CLIENT_ID'], ENV['MOGREET_TOKEN'])
|
26
|
+
response = client.transaction.send(
|
27
|
+
:campaign_id => ENV['MOGREET_SMS_CAMPAIGN_ID'],
|
28
|
+
:to => '1111111111',
|
29
|
+
:message => 'hello world'
|
30
|
+
)
|
31
|
+
|
32
|
+
__Send SMS to list of recipients__
|
33
|
+
|
34
|
+
client = Mogreet::Client.new(ENV['MOGREET_CLIENT_ID'], ENV['MOGREET_TOKEN'])
|
35
|
+
response = client.list.send(
|
36
|
+
:campaign_id => ENV['MOGREET_SMS_CAMPAIGN_ID'],
|
37
|
+
:message => 'hello world',
|
38
|
+
:list_id => '8228'
|
39
|
+
)
|
40
|
+
|
41
|
+
|
42
|
+
__Upload File__
|
43
|
+
|
44
|
+
client = Mogreet::Client.new(ENV['MOGREET_CLIENT_ID'], ENV['MOGREET_TOKEN'])
|
45
|
+
response = client.media.upload(
|
46
|
+
:name => 'upload name',
|
47
|
+
:type => 'image',
|
48
|
+
:file => File.new("image.jpg")
|
49
|
+
)
|
2
50
|
|
3
|
-
TODO: Write a gem description
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
gem 'mogreet'
|
10
|
-
|
11
|
-
And then execute:
|
12
|
-
|
13
|
-
$ bundle
|
14
|
-
|
15
|
-
Or install it yourself as:
|
16
|
-
|
17
|
-
$ gem install mogreet
|
18
|
-
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
|
-
|
23
|
-
## Contributing
|
24
|
-
|
25
|
-
1. Fork it
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
#!/usr/bin/env rake
|
2
1
|
require "bundler/gem_tasks"
|
3
|
-
require 'rspec/core/rake_task'
|
4
2
|
|
5
|
-
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.test_files = FileList['spec/*_spec.rb']
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :test
|
data/lib/mogreet.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
require 'hashie'
|
2
|
-
require 'httparty'
|
3
|
-
require 'crack/xml'
|
4
1
|
|
5
|
-
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
2
|
+
|
3
|
+
require 'mogreet/client'
|
4
|
+
require 'mogreet/response'
|
5
|
+
require 'mogreet/request'
|
6
|
+
require 'mogreet/system'
|
7
|
+
require 'mogreet/transaction'
|
8
|
+
require 'mogreet/user'
|
9
|
+
require 'mogreet/keyword'
|
10
|
+
require 'mogreet/list'
|
11
|
+
require 'mogreet/media'
|
12
|
+
require 'mogreet/deprecated'
|
13
|
+
require 'mogreet/version'
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'hashie'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Mogreet
|
6
|
+
class Client
|
7
|
+
# include Request
|
8
|
+
|
9
|
+
attr_accessor :client_id, :token, :http_response
|
10
|
+
|
11
|
+
def initialize(client_id, token)
|
12
|
+
@client_id = client_id
|
13
|
+
@token = token
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_request(path, query_params = {})
|
17
|
+
params = default_api_args.merge(query_params)
|
18
|
+
@http_response = RestClient.get("https://api.mogreet.com#{path}", {:params => params})
|
19
|
+
Response.new(JSON.parse(@http_response.body)).response
|
20
|
+
end
|
21
|
+
|
22
|
+
def post_request(path, query_params = {})
|
23
|
+
params = default_api_args.merge(query_params)
|
24
|
+
@http_response = RestClient.post("https://api.mogreet.com#{path}", params)
|
25
|
+
Response.new(JSON.parse(@http_response.body)).response
|
26
|
+
end
|
27
|
+
|
28
|
+
def list
|
29
|
+
@list ||= List.new(self)
|
30
|
+
end
|
31
|
+
|
32
|
+
def user
|
33
|
+
@user ||= User.new(self)
|
34
|
+
end
|
35
|
+
|
36
|
+
def media
|
37
|
+
@media ||= Media.new(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
def system
|
41
|
+
@system ||= System.new(self)
|
42
|
+
end
|
43
|
+
|
44
|
+
def keyword
|
45
|
+
@keyword ||= Keyword.new(self)
|
46
|
+
end
|
47
|
+
|
48
|
+
def transaction
|
49
|
+
@transaction ||= Transaction.new(self)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def default_api_args
|
55
|
+
{:client_id => @client_id, :token => @token, :format => 'json'}
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Mogreet
|
4
|
+
class Config < Hashie::Mash ; end
|
5
|
+
|
6
|
+
def self.config
|
7
|
+
@@config ||= Config.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
@@config = Config.new
|
12
|
+
yield config
|
13
|
+
end
|
14
|
+
|
15
|
+
class Response
|
16
|
+
class TransactionSend < Hashie::Mash
|
17
|
+
def transaction_hash
|
18
|
+
self[:hash]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Message
|
24
|
+
class << self
|
25
|
+
def send(options)
|
26
|
+
params = Mogreet.config.merge(options).merge(:format => :json)
|
27
|
+
response = RestClient.get("https://api.mogreet.com/moms/transaction.send", {:params => params.to_hash})
|
28
|
+
Mogreet::Response::TransactionSend.new(JSON.parse(response.body)).response
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# - "{\"client_id\"=>\"714\", \"token\"=>\"a48951eed1e8b093fbea70d882257d84\", \"campaign_id\"=>\"20861\", \"to\"=>\"3104656416\", \"message\"=>\"Hello World!\", \"content_url\"=>\"http://rubyonrails.org/images/rails.png\", \"format\"=>:json}"
|
36
|
+
|
37
|
+
# Configuration
|
38
|
+
# Configure mogreet (add this block to config/initializers/mogreet.rb in case of Rails application):
|
39
|
+
#
|
40
|
+
# Mogreet.configure do |config|
|
41
|
+
# config.client_id = "123"
|
42
|
+
# config.token = "ee91dfa14e59a8600d7976c554f2ed12"
|
43
|
+
# config.campaign_id = "19001"
|
44
|
+
# end
|
45
|
+
# Usage
|
46
|
+
# Send MMS message:
|
47
|
+
#
|
48
|
+
# response = Mogreet::Message.send to: '5551236789',
|
49
|
+
# message: 'Hello World!',
|
50
|
+
# content_url: 'http://rubyonrails.org/images/rails.png'
|
51
|
+
#
|
52
|
+
# response.status #=> "success"
|
53
|
+
# response.code #=> "1"
|
54
|
+
# response.message #=> "Mogreet successfully sent!"
|
55
|
+
# response.message_id #=> 123456789
|
56
|
+
# response.transaction_hash #=> "a12b3c4d"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Mogreet
|
2
|
+
class Keyword
|
3
|
+
def initialize(client)
|
4
|
+
@client = client
|
5
|
+
end
|
6
|
+
|
7
|
+
def list(options ={})
|
8
|
+
@client.get_request('/cm/keyword.list', options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def check(options)
|
12
|
+
@client.get_request('/cm/keyword.check', options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# campaign_id
|
16
|
+
# keyword
|
17
|
+
def add(options)
|
18
|
+
@client.get_request('/cm/keyword.add', options)
|
19
|
+
end
|
20
|
+
|
21
|
+
# campaign_id
|
22
|
+
# keyword
|
23
|
+
def remove(options)
|
24
|
+
@client.get_request('/cm/keyword.remove', options)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/mogreet/list.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Mogreet
|
2
|
+
class List
|
3
|
+
def initialize(client)
|
4
|
+
@client = client
|
5
|
+
end
|
6
|
+
|
7
|
+
def list(options ={})
|
8
|
+
@client.get_request('/cm/list.list', options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def info(options ={})
|
12
|
+
@client.get_request('/cm/list.info', options)
|
13
|
+
end
|
14
|
+
|
15
|
+
# name
|
16
|
+
def create(options ={})
|
17
|
+
@client.get_request('/cm/list.create', options)
|
18
|
+
end
|
19
|
+
|
20
|
+
# list_id
|
21
|
+
# numbers
|
22
|
+
def append(options ={})
|
23
|
+
# TODO clone options?
|
24
|
+
options[:numbers] = options[:numbers].join(',') if options[:numbers].is_a?(Array)
|
25
|
+
@client.get_request('/cm/list.append', options)
|
26
|
+
end
|
27
|
+
|
28
|
+
# list_id
|
29
|
+
# numbers
|
30
|
+
def prune(options ={})
|
31
|
+
# TODO clone options?
|
32
|
+
options[:numbers] = options[:numbers].join(',') if options[:numbers].is_a?(Array)
|
33
|
+
@client.get_request('/cm/list.prune', options)
|
34
|
+
end
|
35
|
+
|
36
|
+
# list_id
|
37
|
+
# campaign_id
|
38
|
+
# subject
|
39
|
+
# message
|
40
|
+
# content_id
|
41
|
+
# content_url
|
42
|
+
# to_name
|
43
|
+
# from_name
|
44
|
+
def send(options)
|
45
|
+
@client.get_request('/cm/list.send', options)
|
46
|
+
end
|
47
|
+
|
48
|
+
# list_id
|
49
|
+
# format
|
50
|
+
def download(options)
|
51
|
+
@client.get_request('/cm/list.download', options)
|
52
|
+
end
|
53
|
+
|
54
|
+
# list_id
|
55
|
+
# name
|
56
|
+
def empty(options)
|
57
|
+
@client.get_request('/cm/list.empty', options)
|
58
|
+
end
|
59
|
+
|
60
|
+
# list_id
|
61
|
+
# name
|
62
|
+
def destroy(options)
|
63
|
+
@client.get_request('/cm/list.destroy', options)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mogreet
|
2
|
+
class Media
|
3
|
+
def initialize(client)
|
4
|
+
@client = client
|
5
|
+
end
|
6
|
+
def list(options = {})
|
7
|
+
@client.get_request('/cm/media.list')
|
8
|
+
end
|
9
|
+
|
10
|
+
def upload(options)
|
11
|
+
@client.post_request('/cm/media.upload', options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def destroy(options)
|
15
|
+
@client.get_request('/cm/media.destroy', options)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mogreet
|
2
|
+
module Request
|
3
|
+
def get_request(path, query_params = {})
|
4
|
+
params = default_api_args.merge(query_params)
|
5
|
+
@http_response = RestClient.get("https://api.mogreet.com#{path}", {:params => params})
|
6
|
+
Response.new(JSON.parse(@http_response.body)).response
|
7
|
+
end
|
8
|
+
|
9
|
+
def post_request(path, query_params = {})
|
10
|
+
params = default_api_args.merge(query_params)
|
11
|
+
@http_response = RestClient.post("https://api.mogreet.com#{path}", params)
|
12
|
+
Response.new(JSON.parse(@http_response.body)).response
|
13
|
+
end
|
14
|
+
|
15
|
+
def default_api_args
|
16
|
+
{:client_id => @client_id, :token => @token, :format => 'json'}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Mogreet
|
2
|
+
class Transaction
|
3
|
+
def initialize(client)
|
4
|
+
@client = client
|
5
|
+
end
|
6
|
+
|
7
|
+
##
|
8
|
+
# campaign_id: An ID connected to a specific campaign
|
9
|
+
# to: The mobile number (MSISDN) of the handset you would like to send to.
|
10
|
+
# from: The mobile number (MSISDN) of the handset you would like to send from. Or the shortcode associated with the campaign. (Optional – if not included, this parameter will default to the shortcode associated to the campaign).
|
11
|
+
# message: The message presented to the "to" user.
|
12
|
+
# content_id: An integer value associated to a piece of content ingested through the Campaign Manager or API.
|
13
|
+
# content_url: A publicly accessible URL of an image, audio or video. MOMS will automagically ingest the content and deliver it as specified by the campaign flow. (Optional, used for SMS and MMS delivering audio, image or video)
|
14
|
+
# callback: If provided with a valid URL, any errors with the transaction will be sent to this URL via XML over HTTP. See description below.
|
15
|
+
def send(options)
|
16
|
+
@client.get_request('/moms/transaction.send', options)
|
17
|
+
end
|
18
|
+
|
19
|
+
# client_id Your client id. Log onto the Campaign Manager to access your client id.
|
20
|
+
# token Your token. Log onto the Campaign Manager to access your token.
|
21
|
+
# message_id A unique ID returned from a successful transaction.send request or from
|
22
|
+
# user.transactions method.
|
23
|
+
# hash A hash returned from a successful transaction.send request or from a
|
24
|
+
# user.transactions method.
|
25
|
+
def lookup(options)
|
26
|
+
# q6z5e0on
|
27
|
+
@client.get_request('/moms/transaction.lookup', options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|