corespring 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a0283546f49a445b6db5c3d2b1662da4dd3868d
4
+ data.tar.gz: b0dce4578a79f1e86bf5d1f517b51c401d07ea44
5
+ SHA512:
6
+ metadata.gz: ae0f56518c3366054b31d4adc8eb2a937b103cadc500f8be10cecbcaa8942c940d2c2b4f5b9df131b87593fc1a13ba114ac11a1df2def7fcf851786fcb9b7946
7
+ data.tar.gz: c3f39d76ada1c1f6e068b55e627433a87e637822d393db9c5f883b111f2096a274293a6717c670ca19d7ab6ff826bd1c8919b0aa51570c614b3330ad913f0c53
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore ADDED
@@ -0,0 +1,52 @@
1
+ # rcov generated
2
+ coverage
3
+ coverage.data
4
+
5
+ # rdoc generated
6
+ rdoc
7
+
8
+ # yard generated
9
+ doc
10
+ .yardoc
11
+
12
+ # bundler
13
+ .bundle
14
+
15
+ # jeweler generated
16
+ pkg
17
+
18
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
19
+ #
20
+ # * Create a file at ~/.gitignore
21
+ # * Include files you want ignored
22
+ # * Run: git config --global core.excludesfile ~/.gitignore
23
+ #
24
+ # After doing this, these files will be ignored in all your git projects,
25
+ # saving you from having to 'pollute' every project you touch with them
26
+ #
27
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
28
+ #
29
+ # For MacOS:
30
+ #
31
+ #.DS_Store
32
+
33
+ # For TextMate
34
+ #*.tmproj
35
+ #tmtags
36
+
37
+ # For emacs:
38
+ #*~
39
+ #\#*
40
+ #.\#*
41
+
42
+ # For vim:
43
+ #*.swp
44
+
45
+ # For redcar:
46
+ #.redcar
47
+
48
+ # For rubinius:
49
+ #*.rbc
50
+
51
+
52
+ .idea/
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ corespring-ruby
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ language: ruby
2
+ script: rspec spec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ platforms :jruby do
5
+ gem 'jruby-openssl'
6
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ corespring (0.0.1)
5
+ builder (>= 2.1.2)
6
+ httparty (>= 0.8)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ addressable (2.3.8)
12
+ builder (3.2.2)
13
+ crack (0.4.2)
14
+ safe_yaml (~> 1.0.0)
15
+ diff-lcs (1.2.5)
16
+ httparty (0.13.3)
17
+ json (~> 1.8)
18
+ multi_xml (>= 0.5.2)
19
+ json (1.8.2)
20
+ multi_xml (0.5.5)
21
+ rake (0.8.7)
22
+ rspec (2.99.0)
23
+ rspec-core (~> 2.99.0)
24
+ rspec-expectations (~> 2.99.0)
25
+ rspec-mocks (~> 2.99.0)
26
+ rspec-core (2.99.2)
27
+ rspec-expectations (2.99.2)
28
+ diff-lcs (>= 1.1.3, < 2.0)
29
+ rspec-mocks (2.99.3)
30
+ safe_yaml (1.0.4)
31
+ webmock (1.6.4)
32
+ addressable (~> 2.2, > 2.2.5)
33
+ addressable (~> 2.2, > 2.2.5)
34
+ crack (>= 0.1.7)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ corespring!
41
+ jruby-openssl
42
+ rake (~> 0.8.7)
43
+ rspec (~> 2.12)
44
+ webmock (~> 1.6.2)
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 CoreSpring
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,57 @@
1
+ == corespring-ruby
2
+
3
+ Build Status: {<img src="https://travis-ci.org/corespring/corespring-ruby.svg" alt="Travis CI">}[https://travis-ci.org/corespring/corespring-ruby]
4
+
5
+ === Installation
6
+
7
+ You can include the +corespring-ruby+ gem directly in your +Gemfile+:
8
+
9
+ gem 'corespring-ruby'
10
+
11
+ See the 'Examples' section about specific API usage.
12
+
13
+ === CLI Examples
14
+
15
+ A command line interface is availably if you install the Gem manually:
16
+
17
+ $ gem install corespring-ruby
18
+
19
+ In conjunction with this, a +~/.corespring+ file can be used to store your credentials:
20
+
21
+ client_id = '553532167c7b5b155a660cc4'
22
+ secret = '7t5cflvx4sc3ou1xhhoefmy5h'
23
+
24
+ ==== Token
25
+
26
+ You can obtain an API token using the +token+ action:
27
+
28
+ $ corespring token
29
+ 8yomydfo7xxob63nlktxoomb1
30
+
31
+ ==== Encrypt
32
+
33
+ You can encrypt options using the +encrypt+ action, specifying +--options+ as follows:
34
+
35
+ $ corespring encrypt --options "{\"mode\": \"gather\"}"
36
+ 50d2cc461f10e4085e1fd23eb640f2ef--5bb672fadeb78c8139c7cc87dfbe3bcb
37
+
38
+ === Library Examples
39
+
40
+ Create a new +CoreSpring::APIClient+ object with your +client_id+ and +secret+:
41
+
42
+ client = CoreSpring::APIClient.new(client_id, secret)
43
+
44
+
45
+ ==== API Token
46
+
47
+ client.get_token # 8yomydfo7xxob63nlktxoomb1
48
+
49
+
50
+ ==== Encrypt Options
51
+
52
+ options = { mode: 'gather' }
53
+ client.encrypt(options) # 130bb4b25f87afc1d825b35afb94596c--7ff4dc0e463b1b0a92705eacd36ac3ea
54
+
55
+ === LICENSE
56
+
57
+ See the {LICENSE.txt}[link:LICENSE.txt] file for more information.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake'
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task :default => :spec
data/bin/corespring ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'corespring-ruby'
4
+ require 'json'
5
+ require 'optparse'
6
+
7
+ options = {
8
+ action: ARGV[0],
9
+ secret: nil,
10
+ client_id: nil
11
+ }
12
+
13
+ global_opts = nil
14
+
15
+ parser = OptionParser.new do |opts|
16
+ global_opts = opts
17
+ opts.banner = [
18
+ "Usage: corespring [action] [options]",
19
+ " Actions:",
20
+ " token: Returns an api token using client_id and secret",
21
+ " Options:"
22
+ ].join("\n")
23
+
24
+ opts.on('--secret secret', 'Secret') do |secret|
25
+ options[:secret] = secret
26
+ end
27
+
28
+ opts.on('--client_id client_id', 'Client ID') do |client_id|
29
+ options[:client_id] = client_id
30
+ end
31
+
32
+ opts.on('-h', '--help', 'Displays Help') do
33
+ options[:help] = true
34
+ puts opts
35
+ exit
36
+ end
37
+
38
+ opts.on('--options options', 'Options to encrypt') do |value|
39
+ options[:options] = JSON.parse(value)
40
+ end
41
+
42
+ end
43
+
44
+ parser.parse!
45
+
46
+ begin
47
+ config = YAML::load(File.open(ENV['HOME'] + '/.corespring'))
48
+ if (options[:client_id].nil?)
49
+ options[:client_id] = config['client_id']
50
+ end
51
+ if (options[:secret].nil?)
52
+ options[:secret] = config['secret']
53
+ end
54
+ rescue Errno::ENOENT
55
+ rescue Psych::SyntaxError
56
+ puts "YAML configuration file contains invalid syntax. Using defaults."
57
+ end
58
+
59
+ if (options[:action].nil?)
60
+ puts global_opts
61
+ elsif (options[:action] == 'token')
62
+ client = CoreSpring::APIClient.new(options[:client_id], options[:secret])
63
+ puts client.get_token
64
+ elsif (options[:action] == 'encrypt')
65
+ client = CoreSpring::APIClient.new(options[:client_id], options[:secret])
66
+ puts client.encrypt(options[:options])
67
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "corespring/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "corespring"
7
+ s.version = CoreSpring::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Ben Burton"]
10
+ s.email = ["developers@corespring.org"]
11
+ s.homepage = "https://github.com/corespring/corespring-ruby"
12
+ s.summary = %q{CoreSpring API Client}
13
+ s.description = %q{CoreSpring API wrapper}
14
+
15
+ s.rubyforge_project = "corespring"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = ['corespring']
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "builder", ">= 2.1.2"
23
+ s.add_dependency "httparty", ">= 0.8"
24
+
25
+ {
26
+ 'rake' => '~> 0.8.7',
27
+ 'rspec' => '~> 2.12',
28
+ 'webmock' => '~> 1.6.2'
29
+ }.each { |l, v| s. add_development_dependency l, v }
30
+ end
@@ -0,0 +1,46 @@
1
+ module CoreSpring
2
+ class APIClient
3
+
4
+ def initialize(client_id, client_secret)
5
+ @client_id = client_id
6
+ @client_secret = client_secret
7
+ end
8
+
9
+ def get_token
10
+ if @token.nil?
11
+ result = CoreSpring.post('/auth/access_token', body: {
12
+ client_id: @client_id,
13
+ client_secret: @client_secret
14
+ })
15
+ if result.code == 200
16
+ @token = JSON.parse(result.body)['access_token']
17
+ else
18
+ throw :invalid_credentials
19
+ end
20
+ end
21
+ @token
22
+ end
23
+
24
+ def encrypt(options)
25
+ def digest_key(raw_key)
26
+ digest = Digest::MD5.new
27
+ digest.update(raw_key)
28
+ digest.digest
29
+ end
30
+
31
+ aes = OpenSSL::Cipher::Cipher.new("AES-128-CBC")
32
+ iv = aes.random_iv
33
+ iv_hexed = iv.unpack('H*')[0]
34
+ key = digest_key(@client_secret)
35
+ aes.encrypt
36
+ aes.key = key
37
+ aes.iv = iv
38
+ cipher = aes.update(JSON.dump(options))
39
+ cipher << aes.final
40
+
41
+ encrypted_hexed = cipher.unpack('H*')[0]
42
+ "#{encrypted_hexed}--#{iv_hexed}"
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module CoreSpring
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'httparty'
2
+ require 'corespring/api_client'
3
+
4
+ module CoreSpring
5
+ include HTTParty
6
+ self.base_uri 'https://platform.corespring.org'
7
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'CoreSpring::APIClient' do
4
+
5
+ let(:client_id) { SecureRandom.hex(13) }
6
+ let(:client_secret) { SecureRandom.hex(13) }
7
+ let(:client) { CoreSpring::APIClient.new(client_id, client_secret) }
8
+
9
+ describe 'get_token' do
10
+
11
+ describe 'with valid client_id and client_secret' do
12
+ let(:token) { SecureRandom.hex(13) }
13
+ subject { client.get_token }
14
+
15
+ before {
16
+ stub_request(:post, "https://platform.corespring.org/auth/access_token")
17
+ .with(:body => "client_id=#{client_id}&client_secret=#{client_secret}")
18
+ .to_return(:status => 200, body: ({ access_token: token }.to_json))
19
+ }
20
+
21
+ it { should == token }
22
+
23
+ end
24
+
25
+ describe 'with invalid client_id and client_secret' do
26
+ subject { client.get_token }
27
+ before {
28
+ stub_request(:post, "https://staging.corespring.org/auth/access_token")
29
+ .with(:body => "client_id=#{client_id}&client_secret=#{client_secret}")
30
+ .to_return(:status => 403, body: ({"code" => 100, "message" => "Invalid credentials", "moreInfo" => ""}.to_json))
31
+ }
32
+
33
+ it 'raises an error' do
34
+ expect { subject }.to raise_error
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ describe 'encrypt' do
42
+ let(:options) { {} }
43
+ subject { client.encrypt(options) }
44
+
45
+ it { should be_a(String) }
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,15 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+
4
+ require 'corespring-ruby'
5
+
6
+ require 'webmock/rspec'
7
+
8
+ RSpec.configure do |config|
9
+ config.before(:suite) do
10
+ WebMock.disable_net_connect!
11
+ end
12
+ config.after(:suite) do
13
+ WebMock.allow_net_connect!
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: corespring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ben Burton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.8.7
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.6.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 1.6.2
83
+ description: CoreSpring API wrapper
84
+ email:
85
+ - developers@corespring.org
86
+ executables:
87
+ - corespring
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .document
92
+ - .gitignore
93
+ - .ruby-gemset
94
+ - .ruby-version
95
+ - .travis.yml
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - LICENSE.txt
99
+ - README.rdoc
100
+ - Rakefile
101
+ - bin/corespring
102
+ - corespring.gemspec
103
+ - lib/corespring-ruby.rb
104
+ - lib/corespring/api_client.rb
105
+ - lib/corespring/version.rb
106
+ - spec/corespring/api_client_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: https://github.com/corespring/corespring-ruby
109
+ licenses: []
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project: corespring
127
+ rubygems_version: 2.2.2
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: CoreSpring API Client
131
+ test_files:
132
+ - spec/corespring/api_client_spec.rb
133
+ - spec/spec_helper.rb