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.
Files changed (61) hide show
  1. data/.gitignore +6 -6
  2. data/Gemfile +1 -2
  3. data/README.md +49 -28
  4. data/Rakefile +8 -3
  5. data/lib/mogreet.rb +12 -8
  6. data/lib/mogreet/client.rb +60 -0
  7. data/lib/mogreet/deprecated.rb +56 -0
  8. data/lib/mogreet/keyword.rb +27 -0
  9. data/lib/mogreet/list.rb +67 -0
  10. data/lib/mogreet/media.rb +19 -0
  11. data/lib/mogreet/request.rb +19 -0
  12. data/lib/mogreet/response.rb +7 -0
  13. data/lib/mogreet/system.rb +10 -0
  14. data/lib/mogreet/transaction.rb +30 -0
  15. data/lib/mogreet/user.rb +33 -1
  16. data/lib/mogreet/version.rb +2 -2
  17. data/mogreet.gemspec +20 -19
  18. data/spec/cassettes/deprecated_mms.yml +53 -0
  19. data/spec/cassettes/keyword_add.yml +56 -0
  20. data/spec/cassettes/keyword_check.yml +57 -0
  21. data/spec/cassettes/keyword_list.yml +121 -0
  22. data/spec/cassettes/keyword_remove.yml +56 -0
  23. data/spec/cassettes/list_append.yml +61 -0
  24. data/spec/cassettes/list_create.yml +57 -0
  25. data/spec/cassettes/list_destroy.yml +56 -0
  26. data/spec/cassettes/list_download.yml +59 -0
  27. data/spec/cassettes/list_empty.yml +56 -0
  28. data/spec/cassettes/list_info.yml +65 -0
  29. data/spec/cassettes/list_list.yml +63 -0
  30. data/spec/cassettes/list_prune.yml +61 -0
  31. data/spec/cassettes/list_send.yml +56 -0
  32. data/spec/cassettes/media_destroy.yml +61 -0
  33. data/spec/cassettes/media_list.yml +72 -0
  34. data/spec/cassettes/media_upload.yml +3602 -0
  35. data/spec/cassettes/ping_invalid.yml +51 -0
  36. data/spec/cassettes/ping_success.yml +147 -0
  37. data/spec/cassettes/transaction_lookup.yml +74 -0
  38. data/spec/cassettes/transaction_send.yml +101 -0
  39. data/spec/cassettes/user_info_success.yml +56 -0
  40. data/spec/cassettes/user_lookup_success.yml +104 -0
  41. data/spec/cassettes/user_transactions_success.yml +62 -0
  42. data/spec/cassettes/user_uncache_success.yml +56 -0
  43. data/spec/deprecated_spec.rb +37 -0
  44. data/spec/fixtures/api.jpg +0 -0
  45. data/spec/keyword_spec.rb +84 -0
  46. data/spec/list_spec.rb +193 -0
  47. data/spec/media_spec.rb +67 -0
  48. data/spec/ping_spec.rb +43 -0
  49. data/spec/spec_helper.rb +26 -7
  50. data/spec/transaction_spec.rb +53 -0
  51. data/spec/user_spec.rb +66 -0
  52. metadata +93 -59
  53. data/.rspec +0 -1
  54. data/LICENSE +0 -22
  55. data/lib/mogreet/config.rb +0 -3
  56. data/lib/mogreet/message.rb +0 -8
  57. data/lib/mogreet/mogreet.rb +0 -13
  58. data/lib/mogreet/response/transaction_send.rb +0 -5
  59. data/spec/fixtures/transaction_send.xml +0 -6
  60. data/spec/mogreet/config_spec.rb +0 -17
  61. 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
- doc/
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
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source 'http://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in mogreet.gemspec
4
3
  gemspec
data/README.md CHANGED
@@ -1,29 +1,50 @@
1
- # Mogreet
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
- RSpec::Core::RakeTask.new('spec')
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
@@ -1,9 +1,13 @@
1
- require 'hashie'
2
- require 'httparty'
3
- require 'crack/xml'
4
1
 
5
- require "mogreet/mogreet"
6
- require "mogreet/version"
7
- require "mogreet/config"
8
- require "mogreet/message"
9
- require "mogreet/response/transaction_send"
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
@@ -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,7 @@
1
+ module Mogreet
2
+ class Response < Hashie::Mash
3
+ def hash
4
+ self[:hash]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module Mogreet
2
+ class System
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+ def ping(options = {})
7
+ @client.get_request('/moms/system.ping')
8
+ end
9
+ end
10
+ 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