opencpu 0.4.0

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: 80e23592402ef0e7144b60fe3fdf523f911f3d6b
4
+ data.tar.gz: 39af7f9a7ecb1975536383491de69b5c734c9e7c
5
+ SHA512:
6
+ metadata.gz: 2a6fd3aae53df745326ed6f5a04657c15dd2eb9850d2b63d0dbb9119d27c33ea89f232fe8776ecbee59544cb480785963077c1c24d4b8cfdfec2c98ad1493b49
7
+ data.tar.gz: 601a69a6d3d9bf7c1b21dbd59a1e29365c7bc38b008b6734a2f1463591efe151e942fd369511fe79c4f9a33032854309fc7617960161fbb386322de2e3084ed4
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .DS_Store
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in opencpu.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard :bundler do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard :rspec do
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ watch('spec/spec_helper.rb') { "spec" }
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 RoQua
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,30 @@
1
+ # Roqua::OpenCPU
2
+
3
+ Roqua wrapper for the OpenCPU REST API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'opencpu'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install opencpu
18
+
19
+ ## Usage
20
+
21
+ data = { '.someFunction': [{ x: [1,2,3,4,5], y: [7,3,9,4,1] }]}
22
+ response = OpenCPU.execute 'PackageName', 'ScriptName', data
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it ( http://github.com/roqua/opencpu/fork )
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/circle.yml ADDED
@@ -0,0 +1,3 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.1.0
data/lib/opencpu.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'httparty'
2
+ require 'yajl'
3
+
4
+ begin
5
+ require "pry"
6
+ rescue LoadError
7
+ end
8
+
9
+
10
+ module OpenCPU
11
+
12
+ class << self
13
+ attr_writer :configuration
14
+ end
15
+
16
+ def self.client
17
+ OpenCPU::Client.new
18
+ end
19
+
20
+ def self.configuration
21
+ @configuration ||= OpenCPU::Configuration.new
22
+ end
23
+
24
+ def self.configure
25
+ yield(configuration)
26
+ end
27
+ end
28
+
29
+
30
+ require "opencpu/configuration"
31
+ require "opencpu/client"
32
+ require "opencpu/version"
@@ -0,0 +1,37 @@
1
+ module OpenCPU
2
+ class Client
3
+ class UnsupportedHTTPMethod < StandardError; end
4
+ include HTTParty
5
+ format :json
6
+ headers 'Content-Type' => 'application/json'
7
+
8
+ def initialize
9
+ self.class.base_uri OpenCPU.configuration.endpoint_url
10
+ end
11
+
12
+ def default_options
13
+ {
14
+ basic_auth: {
15
+ username: OpenCPU.configuration.username,
16
+ password: OpenCPU.configuration.password
17
+ }
18
+ }
19
+ end
20
+
21
+ def execute(package, function, data = {}, method = :post)
22
+ raise UnsupportedHTTPMethod if unsupported_http_method? method
23
+ options = default_options.merge body: data.to_json
24
+ self.class.send(method, "/library/#{package}/R/#{function}/json", options)
25
+ end
26
+
27
+ private
28
+
29
+ def supported_http_methods
30
+ [:post]
31
+ end
32
+
33
+ def unsupported_http_method?(method)
34
+ !supported_http_methods.include? method
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module OpenCPU
2
+ class Configuration
3
+ attr_accessor :endpoint_url
4
+ attr_accessor :username
5
+ attr_accessor :password
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module OpenCPU
2
+ VERSION = "0.4.0"
3
+ end
data/opencpu.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'opencpu/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "opencpu"
8
+ spec.version = OpenCPU::VERSION
9
+ spec.authors = ["Ivan Malykh"]
10
+ spec.email = ["ivan@roqua.nl"]
11
+ spec.summary = %q{Wrapper around OpenCPU REST API}
12
+ spec.description = %q{This gem wraps the OpenCPU REST API.}
13
+ spec.homepage = "http://roqua.nl"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency 'yajl-ruby', '~> 1.2.0'
22
+ spec.add_dependency 'httparty', '~> 0.12.0'
23
+ spec.add_development_dependency 'bundler', '~> 1.5'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rspec', '~> 2.14.1'
26
+ spec.add_development_dependency 'webmock'
27
+ spec.add_development_dependency 'vcr', '~> 2.9.0'
28
+ spec.add_development_dependency 'guard-rspec'
29
+ spec.add_development_dependency 'guard-bundler'
30
+ end
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://foo:bar@public.opencpu.org/ocpu/library/digest/R/hmac/json
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"key":"baz","object":"qux"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ response:
13
+ status:
14
+ code: 200
15
+ message: OK
16
+ headers:
17
+ Server:
18
+ - nginx/1.4.1 (Ubuntu)
19
+ Date:
20
+ - Thu, 10 Apr 2014 12:28:02 GMT
21
+ Content-Type:
22
+ - application/json
23
+ Location:
24
+ - https://public.opencpu.org/ocpu/tmp/x030f9d57/
25
+ Transfer-Encoding:
26
+ - chunked
27
+ Connection:
28
+ - keep-alive
29
+ Cache-Control:
30
+ - max-age=300, public
31
+ X-Ocpu-Session:
32
+ - x030f9d57
33
+ Access-Control-Allow-Origin:
34
+ - "*"
35
+ Access-Control-Allow-Headers:
36
+ - Origin, Content-Type, Accept, Cache-Control
37
+ Access-Control-Expose-Headers:
38
+ - Location, X-ocpu-session, Content-Type, Cache-Control
39
+ X-Ocpu-R:
40
+ - R version 3.1.0 beta (2014-03-28 r65330)
41
+ X-Ocpu-Locale:
42
+ - en_US.UTF-8
43
+ X-Ocpu-Time:
44
+ - 2014-04-10 05:28:02 PDT
45
+ X-Ocpu-Version:
46
+ - 1.2.99
47
+ X-Ocpu-Server:
48
+ - rApache
49
+ X-Ocpu-Cache:
50
+ - MISS
51
+ body:
52
+ encoding: UTF-8
53
+ string: "[\n\t\"22e2a7a268bf076801eefe7cd0119bb9\"\n]\n"
54
+ http_version:
55
+ recorded_at: Thu, 10 Apr 2014 12:28:03 GMT
56
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../../spec_helper.rb', __dir__)
2
+
3
+ describe OpenCPU do
4
+
5
+ it 'responds to #client' do
6
+ expect(described_class).to respond_to :client
7
+ end
8
+
9
+ it 'responds to #configure' do
10
+ expect(described_class).to respond_to :configure
11
+ end
12
+
13
+ it 'responds to #configuration' do
14
+ expect(described_class).to respond_to :configuration
15
+ end
16
+
17
+ describe '#configure' do
18
+ before do
19
+ described_class.configure do |config|
20
+ config.endpoint_url = 'http://somehost.com/opencpu'
21
+ end
22
+ end
23
+
24
+ it "can configure" do
25
+ expect(described_class.configuration.endpoint_url).to eq 'http://somehost.com/opencpu'
26
+ end
27
+ end
28
+
29
+ describe '#client' do
30
+
31
+ end
32
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenCPU::Client do
4
+
5
+ it 'initializes with HTTParty' do
6
+ expect(described_class.ancestors).to include HTTParty
7
+ end
8
+
9
+ it 'provides #default_options' do
10
+ expect(described_class.new).to respond_to :default_options
11
+ end
12
+
13
+ context 'configured' do
14
+ before do
15
+ OpenCPU.configure do |config|
16
+ config.endpoint_url = 'https://public.opencpu.org/ocpu'
17
+ config.username = 'foo'
18
+ config.password = 'bar'
19
+ end
20
+ end
21
+
22
+ it 'initializes with configured attributes' do
23
+ expect(described_class.new.class.base_uri).to eq 'https://public.opencpu.org/ocpu'
24
+ expect(described_class.new.default_options).to eq({basic_auth: {username: 'foo', password: 'bar'}})
25
+ end
26
+ end
27
+
28
+ it 'defines #execute' do
29
+ expect(described_class.new).to respond_to :execute
30
+ end
31
+
32
+ describe '#execute' do
33
+ before do
34
+ OpenCPU.configure do |config|
35
+ config.endpoint_url = 'https://public.opencpu.org/ocpu'
36
+ config.username = 'foo'
37
+ config.password = 'bar'
38
+ end
39
+ end
40
+
41
+ let(:client) { described_class.new }
42
+
43
+ it 'returns a correct HMAC response' do
44
+ VCR.use_cassette :digest_hmac do
45
+ response = client.execute('digest', 'hmac', key: 'baz', object: 'qux')
46
+ expect(response[0]).to eq '22e2a7a268bf076801eefe7cd0119bb9'
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenCPU::Configuration do
4
+
5
+ it 'has an #endpoint_url' do
6
+ expect(described_class.new).to respond_to :endpoint_url
7
+ end
8
+
9
+ it 'has a #username' do
10
+ expect(described_class.new).to respond_to :username
11
+ end
12
+
13
+ it 'has a #password' do
14
+ expect(described_class.new).to respond_to :password
15
+ end
16
+
17
+ describe '#endpoint_url=' do
18
+ it 'sets an url' do
19
+ config = described_class.new
20
+ config.endpoint_url = 'http://test.com'
21
+ expect(config.endpoint_url).to eq 'http://test.com'
22
+ end
23
+ end
24
+
25
+ describe '#username=' do
26
+ it 'sets a username' do
27
+ config = described_class.new
28
+ config.username = 'foo'
29
+ expect(config.username).to eq 'foo'
30
+ end
31
+ end
32
+
33
+ describe '#password=' do
34
+ it 'sets the password' do
35
+ config = described_class.new
36
+ config.password = 'bar'
37
+ expect(config.password).to eq 'bar'
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,8 @@
1
+ require 'vcr'
2
+
3
+ require File.expand_path('../lib/opencpu.rb', __dir__)
4
+
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
7
+ c.hook_into :webmock
8
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opencpu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Malykh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yajl-ruby
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.0
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.12.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.12.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 2.14.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 2.14.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 2.9.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 2.9.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: This gem wraps the OpenCPU REST API.
140
+ email:
141
+ - ivan@roqua.nl
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - .gitignore
147
+ - Gemfile
148
+ - Guardfile
149
+ - LICENSE.txt
150
+ - README.md
151
+ - Rakefile
152
+ - circle.yml
153
+ - lib/opencpu.rb
154
+ - lib/opencpu/client.rb
155
+ - lib/opencpu/configuration.rb
156
+ - lib/opencpu/version.rb
157
+ - opencpu.gemspec
158
+ - spec/fixtures/vcr_cassettes/digest_hmac.yml
159
+ - spec/lib/opencpu.rb
160
+ - spec/lib/opencpu/client_spec.rb
161
+ - spec/lib/opencpu/configuration_spec.rb
162
+ - spec/spec_helper.rb
163
+ homepage: http://roqua.nl
164
+ licenses:
165
+ - MIT
166
+ metadata: {}
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubyforge_project:
183
+ rubygems_version: 2.0.3
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: Wrapper around OpenCPU REST API
187
+ test_files:
188
+ - spec/fixtures/vcr_cassettes/digest_hmac.yml
189
+ - spec/lib/opencpu.rb
190
+ - spec/lib/opencpu/client_spec.rb
191
+ - spec/lib/opencpu/configuration_spec.rb
192
+ - spec/spec_helper.rb