code_broker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in code_broker.gemspec
4
+ gemspec
@@ -0,0 +1,41 @@
1
+ # Code Broker Ruby Client
2
+
3
+ This is a gem for interacting with [Code Broker](http://codebroker.com)'s API
4
+
5
+ ## Example Usage
6
+
7
+ Put this in some initialization code. In rails for instance:
8
+ `config/initializers/codebroker.rb`.
9
+
10
+ ``` ruby
11
+ CodeBroker.configure do |c|
12
+ c.account_id = "<account id>"
13
+ c.access_key = "<access key>"
14
+ c.program = "<program>"
15
+ c.short_code = "<short code>"
16
+ end
17
+ ```
18
+
19
+ In a background job (this example is compatible with Resque):
20
+
21
+ ``` ruby
22
+ class CodeBrokerOptinWorker
23
+ @queue = :critical
24
+
25
+ def self.perform(number, hour, timezone, program=nil)
26
+ # logger.info("Opting in #{number} to program '#{program}'")
27
+
28
+ response = CodeBroker.optin(number,
29
+ :hour => hour,
30
+ :timezone => timezone,
31
+ :program => program
32
+ )
33
+
34
+ # logger.info("Response: #{response.body}")
35
+
36
+ if response.body[/<body>(\d{3})/, 1].to_i != 200
37
+ raise "Bad Response for number #{number}, hour #{hour}, timezone #{timezone}: #{response.body}"
38
+ end
39
+ end
40
+ end
41
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "code_broker/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "code_broker"
7
+ s.version = CodeBroker::VERSION
8
+ s.authors = ["Ben Marini"]
9
+ s.email = ["ben.marini@akqa.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Client library to interface with Code Broker}
12
+ s.description = %q{Client library to interface with Code Broker}
13
+
14
+ s.rubyforge_project = "code_broker"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+
25
+ s.add_dependency "httparty", "~> 0.8.0"
26
+ end
@@ -0,0 +1,89 @@
1
+ require 'httparty'
2
+
3
+ class CodeBroker
4
+ autoload :Connection, "code_broker/connection"
5
+ autoload :Config, "code_broker/config"
6
+
7
+ # Optin a phone number to a program.
8
+ #
9
+ # number - Phone number to opt-in.
10
+ # opts - The Hash options used to refine the selection (default: {}):
11
+ # :hour - Hour of the day the user wants to recieve the message.
12
+ # in 24 hour time.
13
+ # :timezone - Timezone the user wants to recieve the message.
14
+ # :day - Day of the week the user wants to recieve the message,
15
+ # Sunday-Saturday is 1-7.
16
+ # :program - Program to opt-in to. (Defaults to global config)
17
+ # :short_code - Short code to opt-in with. (Defaults to global config)
18
+ #
19
+ # Usage: CodeBroker.optin("14155551212", :hour => "14", :timezone => "EST", :day => 1)
20
+
21
+ def self.optin(number, opts)
22
+ Connection.get("/scoptin.jsp",
23
+ :query => {
24
+ :spn => number,
25
+ :upref => "yes",
26
+ :uprefhod => opts[:hour],
27
+ :uprefustz => opts[:timezone],
28
+ :uprefdow => opts[:day],
29
+ :program => ( opts[:program] || Config.program ),
30
+ :msc => ( opts[:short_code] || Config.short_code )
31
+ }
32
+ )
33
+ end
34
+
35
+ # Send a real time message.
36
+ #
37
+ # number - Phone number to send message to.
38
+ # opts - The Hash options used to refine the selection (default: {}):
39
+ # :program - Program. (Defaults to global config)
40
+ # :short_code - Short code. (Defaults to global config)
41
+ #
42
+ # Usage: CodeBroker.rtm("14155551212", :program => 'PROGRAM')
43
+
44
+ def self.rtm(number, opts) # rtm = real time message
45
+ raise 'Missing key/value in options: :program. Program is required.' unless opts[:program]
46
+ Connection.get("/sckwd.jsp",
47
+ :query => {
48
+ :spn => number,
49
+ :program => opts[:program],
50
+ :msc => ( opts[:short_code] || Config.short_code )
51
+ }
52
+ )
53
+ end
54
+
55
+ # Opt out of a program.
56
+ #
57
+ # number - Phone number to opt out.
58
+ # opts - The Hash options used to refine the selection (default: {}):
59
+ # :program - Program. (Defaults to global config)
60
+ # :short_code - Short code. (Defaults to global config)
61
+ #
62
+ # Usage: CodeBroker.optout("14155551212", :program => 'PROGRAM')
63
+
64
+ def self.optout(number)
65
+ Connection.get("/scoptout.jsp",
66
+ :query => {
67
+ :spn => number,
68
+ :program => Config.program,
69
+ :msc => Config.short_code
70
+ }
71
+ )
72
+ end
73
+
74
+ # Set global configurations for all requests
75
+ #
76
+ # Usage:
77
+ #
78
+ # CodeBroker.configure do |c|
79
+ # c.account_id = "<account id>"
80
+ # c.access_key = "<access key>"
81
+ # c.program = "<program>"
82
+ # c.short_code = "<short code>"
83
+ # end
84
+ #
85
+
86
+ def self.configure
87
+ yield Config if block_given?
88
+ end
89
+ end
@@ -0,0 +1,15 @@
1
+ class CodeBroker
2
+ class Config
3
+ class << self
4
+ attr_accessor :program, :short_code
5
+ end
6
+
7
+ def self.account_id=(val)
8
+ Connection.default_params[:cbid] = val
9
+ end
10
+
11
+ def self.access_key=(val)
12
+ Connection.default_params[:key] = val
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ class CodeBroker
2
+ class Connection
3
+ include HTTParty
4
+ format :html
5
+ base_uri "https://codebroker.net/cb/gateway/get"
6
+
7
+ if ENV['CB_DEBUG']
8
+ debug_output $stderr # For debugging
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module CodeBroker
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: code_broker
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Ben Marini
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-19 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: httparty
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 63
29
+ segments:
30
+ - 0
31
+ - 8
32
+ - 0
33
+ version: 0.8.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: Client library to interface with Code Broker
37
+ email:
38
+ - ben.marini@akqa.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files: []
44
+
45
+ files:
46
+ - .gitignore
47
+ - Gemfile
48
+ - REAME.md
49
+ - Rakefile
50
+ - code_broker.gemspec
51
+ - lib/code_broker.rb
52
+ - lib/code_broker/config.rb
53
+ - lib/code_broker/connection.rb
54
+ - lib/code_broker/version.rb
55
+ homepage: ""
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project: code_broker
84
+ rubygems_version: 1.8.10
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Client library to interface with Code Broker
88
+ test_files: []
89
+