switchcoder 0.0.1

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.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,7 @@
1
+ --markup markdown
2
+ --markup-provider redcarpet
3
+ --charset utf-8
4
+ --readme README.md
5
+ -
6
+ README.md
7
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in switchcoder.gemspec
4
+ gemspec
5
+
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ switchcoder (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ json (1.7.7)
11
+ redcarpet (1.17.2)
12
+ rspec-core (2.12.2)
13
+ rspec-expectations (2.12.1)
14
+ diff-lcs (~> 1.1.3)
15
+ yard (0.7.5)
16
+
17
+ PLATFORMS
18
+ ruby
19
+
20
+ DEPENDENCIES
21
+ json (~> 1.7.7)
22
+ redcarpet (~> 1.17)
23
+ rspec-core (~> 2.0)
24
+ rspec-expectations (~> 2.0)
25
+ switchcoder!
26
+ yard (~> 0.7.5)
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 SwitchCoder
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.
@@ -0,0 +1,80 @@
1
+ # Switchcoder
2
+
3
+ This gem provides a simple API wrapper to access SwitchCoder from any ruby app.
4
+
5
+ It is just now getting started.
6
+
7
+ # Pre-Requisites and Installation
8
+
9
+ ## Prerequisites
10
+
11
+ You will need to create an account on SwitchCoder and create your API token. This client presumes you have a valid account and API token already configured
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'switchcoder'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install switchcoder
26
+
27
+ ## Usage
28
+
29
+ ---
30
+
31
+ ## Initializing the SwitchCoder client
32
+
33
+ require 'switchcoder';
34
+ client = Switchcoder::Client.new('apiToken', 'host');
35
+
36
+ ## Getting a Phone Number Object
37
+
38
+ phone_number = client.phone_number("yourNumber", opts);
39
+
40
+
41
+ ## Getting a Code Object
42
+
43
+ // get an instance of the script from the client
44
+ code = client.code(scriptId, phoneNumber, opts);
45
+
46
+ # Invoking the Code
47
+
48
+ //invoke the code with all parameters
49
+ response = code.invoke(queryParameters, requestBody) {|chunk| puts chunk};
50
+
51
+ //invoke script with just the callback
52
+ response = code.invoke {|chunk| puts chunk};
53
+
54
+ ## Putting it all together
55
+
56
+ require 'switchcoder';
57
+ client = Switchcoder::Client.new('1231232123', 'api.switchcoder.com');
58
+ phone_number = client.phone_number('19195551212');
59
+ code = client.code(123);
60
+ request_parameters = {parameter1:'parameter1Value', parameter2:'parameter2Value'};
61
+ request_body = {bodyValue1:'my text'};
62
+
63
+ response = code.invoke(request_parameters, request_body)
64
+
65
+ case response
66
+ when Net::HTTPSuccess
67
+ puts "Response status: #{response.code} with data: #{response.body}"
68
+ else
69
+ puts "Got an error: #{response.message}"
70
+ end
71
+
72
+ ---
73
+
74
+ ## Contributing
75
+
76
+ 1. Fork it
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 4. Push to the branch (`git push origin my-new-feature`)
80
+ 5. Create new Pull Request
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'yard'
3
+ require 'rspec/core/rake_task'
4
+
5
+ # for "rake yard" task
6
+ YARD::Rake::YardocTask.new
7
+
8
+ # for "rake spec"
9
+ RSpec::Core::RakeTask.new
10
+
11
+ task :test => :spec
@@ -0,0 +1,9 @@
1
+ require "switchcoder/version"
2
+
3
+ module Switchcoder
4
+
5
+ end
6
+
7
+ require 'switchcoder/phone_number'
8
+ require 'switchcoder/client'
9
+ require 'switchcoder/code'
@@ -0,0 +1,24 @@
1
+ module Switchcoder
2
+
3
+ class Client
4
+
5
+ attr_reader :host, :api_token, :opts
6
+
7
+ def initialize(api_token, host = nil, opts = nil)
8
+ @api_token = api_token;
9
+ @host = host || 'api.switchcoder.com';
10
+ @opts = (opts || {}).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
11
+ end
12
+
13
+ def phone_number(num,opts = nil)
14
+ PhoneNumber.new(num, opts)
15
+ end
16
+
17
+ def code(id, phone_number = nil, opts = nil)
18
+ script = Code.new(id, phone_number, opts)
19
+ script.client = self
20
+ return script
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,54 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+
4
+ module Switchcoder
5
+
6
+ class Code
7
+
8
+ attr_accessor :client
9
+ attr_reader :id, :phone_number, :opts
10
+
11
+ def initialize(id, phone_number = nil, opts = nil)
12
+ @id = id;
13
+ @phone_number = phone_number;
14
+ @opts = opts;
15
+ end
16
+
17
+ # This method returns a Net::HTTPResponse object.
18
+ #
19
+ # If called with a block, yields each fragment of the entity body
20
+ # in turn as a string as it is read from the socket.
21
+ # Note that in this case, the returned response object will not contain a (meaningful) body.
22
+
23
+ def invoke(query_parameters = {}, body = "", query_headers = nil)
24
+ query_parameters ||= {}
25
+ body ||= ""
26
+
27
+ headers = {'Content-Type' => 'application/json', 'api_token' => client.api_token.to_s}
28
+ headers["phone_number"] = @phone_number.number.to_s if @phone_number
29
+
30
+ # add user headers to common headers
31
+ headers.merge!( query_headers ) if query_headers
32
+
33
+
34
+ uri = URI("https://#{client.host}/code/#{@id}/invoke")
35
+ uri.query = URI.encode_www_form(query_parameters)
36
+
37
+ http = Net::HTTP.new( uri.host, uri.port )
38
+ http.use_ssl = (uri.scheme == 'https')
39
+
40
+ res = http.start do |http|
41
+ if client.opts[:method].to_s.downcase == 'get'
42
+ http.get(uri.request_uri, headers) { |str| yield str if block_given? }
43
+ else
44
+ headers['Content-Length'] = body.length.to_s
45
+ http.post(uri.request_uri, body, headers) { |str| yield str if block_given? }
46
+ end
47
+ end
48
+
49
+ return res
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,13 @@
1
+ module Switchcoder
2
+
3
+ class PhoneNumber
4
+
5
+ attr_reader :number
6
+
7
+ def initialize(num, opts = nil)
8
+ @number = num;
9
+ @opts = opts;
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,3 @@
1
+ module Switchcoder
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,32 @@
1
+ require 'json'
2
+ require 'spec_helper'
3
+
4
+ describe Switchcoder do
5
+ it "should do GET and return Net::HTTPResponse" do
6
+
7
+ client = Switchcoder::Client.new('1231232123', 'api.switchcoder.com', method: :get);
8
+ phone_number = client.phone_number('19195551212');
9
+ code = client.code(123);
10
+ request_parameters = {parameter1:'parameter1Value', parameter2:'parameter2Value'};
11
+ request_body = {bodyValue1:'my text'};
12
+
13
+ response = code.invoke(request_parameters, request_body.to_json)
14
+
15
+ response.should be_a Net::HTTPResponse
16
+
17
+ end
18
+
19
+ it "should do GET and return Net::HTTPResponse" do
20
+
21
+ client = Switchcoder::Client.new('1231232123', 'api.switchcoder.com');
22
+ phone_number = client.phone_number('19195551212');
23
+ code = client.code(123);
24
+ request_parameters = {parameter1:'parameter1Value', parameter2:'parameter2Value'};
25
+ request_body = {bodyValue1:'my text'};
26
+
27
+ response = code.invoke(request_parameters, request_body.to_json)
28
+
29
+ response.should be_a Net::HTTPResponse
30
+
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require 'switchcoder'
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'switchcoder/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "switchcoder"
8
+ gem.version = Switchcoder::VERSION
9
+ gem.authors = ["Scott Barstow"]
10
+ gem.email = ["scott@switchcoder.com"]
11
+ gem.description = %q{API wrapper to access SwitchCoder}
12
+ gem.summary = %q{This gem provides a simple API wrapper to access SwitchCoder from any ruby app.}
13
+ gem.homepage = "http://switchcoder.com"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ {
21
+ "redcarpet" => "~> 1.17",
22
+ "yard" => "~> 0.7.5",
23
+ "rspec-core" => "~> 2.0",
24
+ "rspec-expectations" => "~> 2.0",
25
+ 'json' => "~> 1.7.7"
26
+ }.each do |lib, version|
27
+ gem.add_development_dependency(lib, *version)
28
+ end
29
+
30
+ #gem.add_runtime_dependency(lib, *version)
31
+
32
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: switchcoder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Scott Barstow
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redcarpet
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.17'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.17'
30
+ - !ruby/object:Gem::Dependency
31
+ name: yard
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.7.5
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.7.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec-core
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-expectations
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.7.7
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.7.7
94
+ description: API wrapper to access SwitchCoder
95
+ email:
96
+ - scott@switchcoder.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rspec
103
+ - .yardopts
104
+ - Gemfile
105
+ - Gemfile.lock
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/switchcoder.rb
110
+ - lib/switchcoder/client.rb
111
+ - lib/switchcoder/code.rb
112
+ - lib/switchcoder/phone_number.rb
113
+ - lib/switchcoder/version.rb
114
+ - spec/lib/switchcoder_spec.rb
115
+ - spec/spec_helper.rb
116
+ - switchcoder.gemspec
117
+ homepage: http://switchcoder.com
118
+ licenses: []
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.24
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: This gem provides a simple API wrapper to access SwitchCoder from any ruby
141
+ app.
142
+ test_files:
143
+ - spec/lib/switchcoder_spec.rb
144
+ - spec/spec_helper.rb