carbon_pms 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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/carbon_pms.gemspec +26 -0
- data/lib/carbon_pms/client.rb +65 -0
- data/lib/carbon_pms/version.rb +3 -0
- data/lib/carbon_pms.rb +24 -0
- data/spec/carbon_pms/client_spec.rb +42 -0
- data/spec/carbon_pms_spec.rb +18 -0
- data/spec/spec_helper.rb +3 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ab132c8bdd45705a23f576dc2dad791b094dd4ab
|
4
|
+
data.tar.gz: 70e2cebc7ce69b4d9029b336c52406ec80ccd102
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8bffdd76d3b79508e3ac1bfa479442d052ce66b46d5ed9dfbaf3932c192430a0736780be0b0ec5fb96ca28b50a44f20bdf5ecbe8fc5dda917001fd193f39cc73
|
7
|
+
data.tar.gz: 94b6513f41533d0e888fdb61bac7a65fac1e999925966cdff6fdc0564b0343e18c362afd5a9ebbde2ad41ac6c1601e00743dea7026c68e3a5b2aafcddab064dc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chris Mason
|
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/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# CarbonPms
|
2
|
+
|
3
|
+
If you're not using a CarbonPMS server, then you don't need this.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'carbon_pms'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install carbon_pms
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
require 'carbon_pms'
|
22
|
+
|
23
|
+
client = CarbonPms::Client.new('example.com', 'auth_token', API_VERSION)
|
24
|
+
client.create_app(name: 'foo', auth_key: '123123')
|
25
|
+
|
26
|
+
You can also initialize the client with a configuration block:
|
27
|
+
|
28
|
+
# config/initializers/carbon_pms.rb (for instance)
|
29
|
+
CarbonPms.configure do |config|
|
30
|
+
config.host = 'example.com'
|
31
|
+
config.auth_token = 'abcdef'
|
32
|
+
config.version = '42'
|
33
|
+
end
|
34
|
+
# elsewhere
|
35
|
+
client = CarbonPms.Client.new
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/carbon_pms.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'carbon_pms/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "carbon_pms"
|
8
|
+
spec.version = CarbonPms::VERSION
|
9
|
+
spec.authors = ["Chris Mason"]
|
10
|
+
spec.email = ["chris@chaione.com"]
|
11
|
+
spec.description = %q{Ruby client to send push messages to a Carbon PMS server.}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = "https://github.com/chaione/carbon_pms"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_dependency 'httparty', '~> 0.10'
|
26
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module CarbonPms
|
2
|
+
class Client
|
3
|
+
include HTTParty
|
4
|
+
format :json
|
5
|
+
|
6
|
+
def initialize(host=CarbonPms.host, auth_token=CarbonPms.auth_token, version=CarbonPms.version)
|
7
|
+
if host.downcase.start_with?('http://', 'https://')
|
8
|
+
self.class.base_uri "#{host}/api"
|
9
|
+
else
|
10
|
+
self.class.base_uri "https://#{host}/api"
|
11
|
+
end
|
12
|
+
self.class.headers('Authorization' => "token #{auth_token}") if auth_token
|
13
|
+
self.class.headers('Accept' => "application/vnd.carbon.pms.v#{version}") if version
|
14
|
+
end
|
15
|
+
|
16
|
+
# Creates either a GCM or APNS app to receive push messages. You must create an app
|
17
|
+
# before you can send push notifications.
|
18
|
+
#
|
19
|
+
# @param [Hash] options hash to construct an app.
|
20
|
+
# Must include :name and (:certificate or :auth_key)
|
21
|
+
# @option options [String] :name A name for this app. The name must be unique within the environment and app type
|
22
|
+
# @option options [String] :environment can be one of the following:
|
23
|
+
# * _production_
|
24
|
+
# * _development_
|
25
|
+
# * _sandbox_
|
26
|
+
# Defaults to _development_
|
27
|
+
# @option options [String] :auth_key Setting this key will create a GCM app. Your Google API key goes here. This option is mutually exclusive with :certificate
|
28
|
+
# @option options [String] :certificate Setting this key will create an APNS app. Your certificate needs to be in _pem_ format. This option is mutually exclusive with :auth_key
|
29
|
+
# @option options [String] :password The password to decrypt the certificate if it was encrypted.
|
30
|
+
# @raise [ArgumentError] if anything is amiss
|
31
|
+
# @return [HTTParty::Response] The response from the server. The following properties may be interesting:
|
32
|
+
# * *body* : the parsed response body
|
33
|
+
# * *code* : the status code
|
34
|
+
# * *message* : the status message
|
35
|
+
# * *headers* : the response headers
|
36
|
+
def create_app(options={})
|
37
|
+
raise ArguementError, 'You must provide an app name' unless options[:name]
|
38
|
+
options[:environment] = 'development' unless %w{production sandbox}.include? options[:environment]
|
39
|
+
return post('/app/apns', body: options) if options.has_key? :certificate
|
40
|
+
return post('/app/gcm', body: options) if options.has_key? :auth_key
|
41
|
+
raise ArguementError, 'You must provide a :certificate or :auth_key'
|
42
|
+
end
|
43
|
+
|
44
|
+
# Sends a push notification to the APNS
|
45
|
+
#
|
46
|
+
# @param [Hash] options hash to construct an app
|
47
|
+
# @option options [String] :device_token the device token to receive this push notification
|
48
|
+
# @option options [String] :app the name of the app
|
49
|
+
# @option options [String] :environment the environment this app is running in _(production, development, sandbox)_
|
50
|
+
# @option options [String] :alert the message to send
|
51
|
+
# @option options [Hash] :data any custom attributes to send
|
52
|
+
# @option options [Integer] :badge sets the badge number to the specified number
|
53
|
+
# @option options [String] :sound play the specified sound when the notification is received.
|
54
|
+
# @option options [Integer] :content_available notify the device that new content is available
|
55
|
+
def apns_notificaton(options={})
|
56
|
+
return post '/push/apns', query: options
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def post(path, options={})
|
62
|
+
self.class.post path, options
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/carbon_pms.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'carbon_pms/version'
|
2
|
+
require 'carbon_pms/client'
|
3
|
+
|
4
|
+
module CarbonPms
|
5
|
+
class << self
|
6
|
+
attr_accessor :host, :auth_token, :version
|
7
|
+
|
8
|
+
# config/initializers/carbon_pms.rb (for instance)
|
9
|
+
#
|
10
|
+
# CarbonPms.configure do |config|
|
11
|
+
# config.host = 'example.com'
|
12
|
+
# config.auth_token = 'abcdef'
|
13
|
+
# config.version = '42'
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# elsewhere
|
17
|
+
#
|
18
|
+
# client = CarbonPms::Client.new
|
19
|
+
def configure
|
20
|
+
yield self
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CarbonPms::Client do
|
4
|
+
context 'initialization' do
|
5
|
+
let(:host) { 'example.com' }
|
6
|
+
let(:auth_token) { nil }
|
7
|
+
let(:version) { nil }
|
8
|
+
let(:client) { CarbonPms::Client.new(host, auth_token, version) }
|
9
|
+
|
10
|
+
context 'defaults' do
|
11
|
+
it 'should default to ssl when given a hostname' do
|
12
|
+
client.class.base_uri.should == 'https://example.com/api'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should not have the authorization header set' do
|
16
|
+
client.class.headers.should_not have_key('Authorization')
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should not have the version header set' do
|
20
|
+
client.class.headers.should_not have_key('Accept')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'custom' do
|
25
|
+
let(:host) { 'http://example.com:5000' }
|
26
|
+
let(:auth_token) { 'abcdef' }
|
27
|
+
let(:version) { 42 }
|
28
|
+
|
29
|
+
it 'should use http if explicitly defined' do
|
30
|
+
client.class.base_uri.should == 'http://example.com:5000/api'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should set the authorization header if given an auth token' do
|
34
|
+
client.class.headers['Authorization'].should eq 'token abcdef'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should set the version header if given a version' do
|
38
|
+
client.class.headers['Accept'].should eq 'application/vnd.carbon.pms.v42'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CarbonPms do
|
4
|
+
it 'should have a version number' do
|
5
|
+
CarbonPms::VERSION.should_not be_nil
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should be able to set its attributes via a configuration block' do
|
9
|
+
CarbonPms.configure do |config|
|
10
|
+
config.host = 'example.com'
|
11
|
+
config.auth_token = 'abcdef'
|
12
|
+
config.version = 42
|
13
|
+
end
|
14
|
+
CarbonPms.host.should == 'example.com'
|
15
|
+
CarbonPms.auth_token.should == 'abcdef'
|
16
|
+
CarbonPms.version.should == 42
|
17
|
+
end
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carbon_pms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Mason
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-18 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: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
description: Ruby client to send push messages to a Carbon PMS server.
|
70
|
+
email:
|
71
|
+
- chris@chaione.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .rspec
|
78
|
+
- .travis.yml
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- carbon_pms.gemspec
|
84
|
+
- lib/carbon_pms.rb
|
85
|
+
- lib/carbon_pms/client.rb
|
86
|
+
- lib/carbon_pms/version.rb
|
87
|
+
- spec/carbon_pms/client_spec.rb
|
88
|
+
- spec/carbon_pms_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: https://github.com/chaione/carbon_pms
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.1.11
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Ruby client to send push messages to a Carbon PMS server.
|
114
|
+
test_files:
|
115
|
+
- spec/carbon_pms/client_spec.rb
|
116
|
+
- spec/carbon_pms_spec.rb
|
117
|
+
- spec/spec_helper.rb
|