transistor-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd19ca5b07bdb3a6002473d0f18e5b074db1ca86
4
+ data.tar.gz: 81a8a25f1cb0fadfeb701a2ef5f4dd29e760af56
5
+ SHA512:
6
+ metadata.gz: 01f12e7b45bd306156213b7b3cc8a8d38914418821368690b16b7c1826469487447bae8f37412114a8f2d34eabcbb4f45820c308aa17a1df82b376c009604cb1
7
+ data.tar.gz: 78fd3eff81637c3152f92f39d065109a8d4ba996c7ec95f5126eb0cf0f50d6d04ed2614556db601ef5d677128d5a189d2a427e8e9e1b667b4f92ad74fe5c6690
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in transistor-client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (C) Original Machine, LLC.
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.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task default: :spec
data/Readme.md ADDED
@@ -0,0 +1,56 @@
1
+ # Transistor
2
+
3
+ Transistor is a powerful digital metrics platform from [Original Machine](http://originalmachine.com) that is currently in beta. This gem provides an interface to the Transistor API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'transistor-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install transistor-client
18
+
19
+ ## Usage
20
+
21
+ First, [sign in](http://transistor.fm) and create an Application. Then, add your credentials, maybe in an initializer:
22
+
23
+ ```ruby
24
+ Transistor.configure do |config|
25
+ config.id = 'xxxxxx'
26
+ config.secret = 'xxxxxx'
27
+ end
28
+ ```
29
+
30
+ You can also override the default settings, if you can't connect via ```https```, or wish to use an alternate host:
31
+
32
+ ```ruby
33
+ Transistor.setup do |config|
34
+ config.host = 'api.transistor.fm'
35
+ config.secure = false
36
+ end
37
+ ```
38
+
39
+ ### Making Requests
40
+
41
+ ```ruby
42
+ client = Transistor::Client.new
43
+ client.get('/channels')
44
+ ```
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create new Pull Request
53
+
54
+ ## License
55
+
56
+ © 2013 Original Machine, LLC. Released under the MIT License.
@@ -0,0 +1,62 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'transistor/middleware/authentication'
4
+ require 'transistor/error'
5
+
6
+ module Transistor
7
+ class Client
8
+ def connection_options
9
+ @collection_options ||= {
10
+ builder: middleware,
11
+ headers: {
12
+ accept: 'application/json',
13
+ user_agent: Transistor.config.user_agent
14
+ },
15
+ request: {
16
+ open_timeout: 5,
17
+ timeout: 10
18
+ }
19
+ }
20
+ end
21
+
22
+ def middleware
23
+ @middleware = Faraday::Builder.new do |builder|
24
+ builder.use Faraday::Request::UrlEncoded
25
+ builder.use Transistor::Middleware::Authentication
26
+ builder.adapter Faraday.default_adapter
27
+ end
28
+ end
29
+
30
+ def delete(path, params = {})
31
+ request(:delete, path, params)
32
+ end
33
+
34
+ def get(path, params = {})
35
+ request(:get, path, params)
36
+ end
37
+
38
+ def post(path, params = {})
39
+ request(:post, path, params)
40
+ end
41
+
42
+ def put(path, params = {})
43
+ request(:put, path, params)
44
+ end
45
+
46
+ private
47
+
48
+ def connection
49
+ @connection ||= Faraday.new Transistor.config.base_url, connection_options do |conn|
50
+ conn.response :json, content_type: /\bjson$/
51
+ end
52
+ end
53
+
54
+ def request(method, path, params = {})
55
+ response = connection.send(method.to_sym, path, params) do |request|
56
+ end
57
+ response.env
58
+ rescue Faraday::Error::ClientError => error
59
+ raise Transistor::Error.new(err)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,7 @@
1
+ module Transistor
2
+ class Error < StandardError
3
+ def initialize(message)
4
+ super(message)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,33 @@
1
+ require 'hawk'
2
+
3
+ module Transistor
4
+ module Middleware
5
+ class Authentication < Faraday::Middleware
6
+ AUTHORIZATION_HEADER = 'Authorization'.freeze
7
+ CONTENT_TYPE_HEADER = 'Content-Type'.freeze
8
+
9
+ def initalize(app, options = {})
10
+ super(app)
11
+ end
12
+
13
+ def call(env)
14
+ env[:request_headers][AUTHORIZATION_HEADER] = authorize_request(env)
15
+ @app.call(env)
16
+ end
17
+
18
+ private
19
+
20
+ def authorize_request(env)
21
+ Hawk::Client.build_authorization_header(
22
+ credentials: Transistor.config.credentials,
23
+ ts: Time.now.to_i,
24
+ content_type: env[:request_headers][CONTENT_TYPE_HEADER].to_s.split(';').first,
25
+ method: env[:method].to_s.upcase,
26
+ port: env[:url].port || (env[:url].scheme == 'https' ? 443 : 80),
27
+ host: env[:url].host,
28
+ request_uri: env[:url].to_s.sub(%r{\A#{env[:url].scheme}://#{env[:url].host}(:#{env[:url].port})?}, '')
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Transistor
2
+ Version = '0.0.1'
3
+ end
data/lib/transistor.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'transistor/version'
2
+ require 'transistor/client'
3
+
4
+ module Transistor
5
+ class << self
6
+ attr_accessor :config
7
+ end
8
+
9
+ class Config
10
+ attr_accessor :id, :secret, :host, :secure
11
+
12
+ def initialize
13
+ @host = 'api.transistor.fm'
14
+ @secure = true
15
+ end
16
+
17
+ def base_url
18
+ if self.secure
19
+ "https://#{self.host}"
20
+ else
21
+ "http://#{self.host}"
22
+ end
23
+ end
24
+
25
+ def credentials
26
+ {
27
+ id: self.id,
28
+ key: self.secret,
29
+ algorithm: 'sha256'
30
+ }
31
+ end
32
+
33
+ def user_agent
34
+ "Transistor Ruby Client, Version #{Transistor::Version}"
35
+ end
36
+ end
37
+
38
+ def self.setup
39
+ self.config ||= Config.new
40
+ yield(config)
41
+ end
42
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Transistor do
4
+ context 'defaults' do
5
+ before do
6
+ Transistor.setup do |config|
7
+ config.id = '103031111'
8
+ config.secret = 'xxxx40'
9
+ end
10
+ end
11
+
12
+ it 'should store configuration information' do
13
+ expect(Transistor.config.id).to eq('103031111')
14
+ expect(Transistor.config.secret).to eq('xxxx40')
15
+ end
16
+
17
+ it 'should default to https' do
18
+ expect(Transistor.config.secure).to eq(true)
19
+ end
20
+
21
+ it 'should default to api.transistor.fm as the host' do
22
+ expect(Transistor.config.host).to eq('api.transistor.fm')
23
+ end
24
+ end
25
+
26
+ context 'Overriding defaults' do
27
+ before do
28
+ Transistor.setup do |config|
29
+ config.id = '1030311101'
30
+ config.secret = 'xxxx400'
31
+ config.host = 'api.transistor.dev'
32
+ config.secure = false
33
+ end
34
+ end
35
+
36
+ it 'should override the host and secure config' do
37
+ expect(Transistor.config.host).to eq('api.transistor.dev')
38
+ expect(Transistor.config.secure).to eq(false)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+ require 'transistor'
3
+
4
+ RSpec.configure do |config|
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'transistor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'transistor-client'
8
+ spec.version = Transistor::Version
9
+ spec.authors = ['Nicholas Young']
10
+ spec.email = ['nicholas@originalmachine.com']
11
+ spec.description = %q{The official Ruby client for Transistor.FM, a digital media analytics platform from Original Machine.}
12
+ spec.summary = %q{A client for the Transistor.FM media analytics platform.}
13
+ spec.homepage = 'http://transistor.fm'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^(spec)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.3'
21
+ spec.add_development_dependency 'rake', '~> 10.1.1'
22
+ spec.add_development_dependency 'rspec', '~> 2.14.1'
23
+
24
+ spec.add_dependency 'faraday', '~> 0.8.8'
25
+ spec.add_dependency 'faraday_middleware', '~> 0.9.0'
26
+ spec.add_dependency 'json', '~> 1.8.1'
27
+ spec.add_dependency 'hawk-auth', '~> 0.2.4'
28
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transistor-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas Young
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 10.1.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 10.1.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.8
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.8.8
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 0.9.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 0.9.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.8.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.8.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: hawk-auth
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.2.4
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.2.4
111
+ description: The official Ruby client for Transistor.FM, a digital media analytics
112
+ platform from Original Machine.
113
+ email:
114
+ - nicholas@originalmachine.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .rspec
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - Rakefile
124
+ - Readme.md
125
+ - lib/transistor.rb
126
+ - lib/transistor/client.rb
127
+ - lib/transistor/error.rb
128
+ - lib/transistor/middleware/authentication.rb
129
+ - lib/transistor/version.rb
130
+ - spec/config_spec.rb
131
+ - spec/spec_helper.rb
132
+ - transistor-client.gemspec
133
+ homepage: http://transistor.fm
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.1.11
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: A client for the Transistor.FM media analytics platform.
157
+ test_files:
158
+ - spec/config_spec.rb
159
+ - spec/spec_helper.rb