assaydepot 0.0.1 → 0.1.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
+ SHA256:
3
+ metadata.gz: ac3e59291589c598212136d3054ea0c5abc24c594b7278f3ab69b28c25fa7509
4
+ data.tar.gz: 3cabe89cd8cd5c7828a6de608ccf5587867ab707bbda355900b6cd9830c50528
5
+ SHA512:
6
+ metadata.gz: e68c24ab5fd611118b446d7a987336a364d062dd772fa2b920b213f4611f08bd64a0895d0501934bc5679e9cfc3d2092d1c9bf5164e4afec34bd1bcb50e78b94
7
+ data.tar.gz: 0c0c9f56eca381700ccb7cdc2c9d25823ecfb932e5b8f297330b976dd7e9504f1a6bcd101223123d66d3b9a2702217c1014c9b07cd4b2bbdb89a861c40064003
data/.gitignore CHANGED
@@ -2,6 +2,7 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
+ .ruby-version
5
6
  .yardoc
6
7
  Gemfile.lock
7
8
  InstalledFiles
@@ -15,3 +16,5 @@ spec/reports
15
16
  test/tmp
16
17
  test/version_tmp
17
18
  tmp
19
+ .env
20
+ ./api.rb
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - 2.1.0
4
+ - 2.3.0
5
+ script:
6
+ - bundle exec rake spec
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
1
  source 'https://rubygems.org'
2
+ gem 'pry'
3
+ gem 'pry-byebug'
4
+ gem 'dotenv-rails', groups: [:development, :test]
2
5
 
3
6
  # Specify your gem's dependencies in assaydepot.gemspec
4
7
  gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,10 @@
1
+ #The MIT License (MIT)
2
+
3
+ Copyright (c) 2012 Assay Depot
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # AssayDepot
1
+ # Scientist.com
2
2
 
3
- Ruby interface for Assay Depot's online laboratory (http://www.assaydepot.com).
3
+ Ruby interface for Scientist.com's (formerly Assay Depot's) research services marketplace (http://www.scientist.com).
4
+
5
+ ## Scientist.com Developer Program
6
+
7
+ An authentication token is required for the API to function. If you would like access to the API, please email support@scientist.com.
4
8
 
5
9
  ## Installation
6
10
 
@@ -18,16 +22,32 @@ Or install it yourself as:
18
22
 
19
23
  ## Basic Usage
20
24
 
25
+ ### Storefront
26
+
21
27
  ```ruby
22
28
  require 'assaydepot'
23
29
  AssayDepot.configure do |config|
24
- config.auth_token = "1234567890"
25
- config.url = "http://localhost:3000/api"
30
+ config.access_token = "1234567890"
31
+ config.url = "https://app.scientist.com"
26
32
  end
27
33
  wares = AssayDepot::Ware.find("Antibody")
28
34
  wares.total
29
35
  ```
30
36
 
37
+ ### Backoffice
38
+
39
+ ```ruby
40
+ require 'assaydepot'
41
+ AssayDepot.configure do |config|
42
+ config.access_token = "1234567890"
43
+ config.url = "https://backoffice.scientist.com"
44
+ end
45
+ quoted_ware = AssayDepot::QuotedWare.get()
46
+ ```
47
+
48
+ ## API Documentation
49
+ See the [Scientist.com API documentation](https://assaydepot.github.io/scientist_api_docs/#introduction) for details on the Scientist.com API resources and code examples using this SDK.
50
+
31
51
  ## Using Facets
32
52
 
33
53
  ```ruby
@@ -45,14 +65,14 @@ wares.first["name"]
45
65
  ## Providers
46
66
 
47
67
  ```ruby
48
- providers = AssayDepot::Provider.where(:starts_with => "a").per_page(600)
68
+ providers = AssayDepot::Provider.where(:starts_with => "a").per_page(50)
49
69
  providers.count
50
70
  ```
51
71
 
52
72
  ## Get Details
53
73
  ```ruby
54
74
  providers = AssayDepot::Provider.where(:starts_with => "a")
55
- AssayDepot::Provider.get(providers.first["id"])
75
+ AssayDepot::Provider.get(id: providers.first["id"])
56
76
  ```
57
77
 
58
78
  ## Contributing
@@ -62,3 +82,7 @@ AssayDepot::Provider.get(providers.first["id"])
62
82
  3. Commit your changes (`git commit -am 'Added some feature'`)
63
83
  4. Push to the branch (`git push origin my-new-feature`)
64
84
  5. Create new Pull Request
85
+
86
+ ## License
87
+
88
+ The Scientist.com Ruby SDK is released under the MIT license.
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :test => :spec
8
+ task :default => :spec
data/assaydepot.gemspec CHANGED
@@ -2,18 +2,24 @@
2
2
  require File.expand_path('../lib/assaydepot/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Christopher Petersen"]
6
- gem.email = ["christopher.petersen@gmail.com"]
7
- gem.description = %q{This is the first version of Assay Depot's Ruby SDK. It provides read access to Services and Vendors through assaydepot.com's JSON API.}
5
+ gem.authors = ["Christopher Petersen", "Ron Ranauro"]
6
+ gem.email = ["chris@scientist.com", "ron@scientist.com"]
7
+ gem.description = %q{The Scientist Ruby SDK. It provides read access to Services and Suppliers through scientist.com's JSON API.}
8
8
  gem.summary = %q{Provides read access to Assay Depot's Services and Vendors.}
9
9
  gem.homepage = "https://github.com/assaydepot/assaydepot-rb"
10
10
 
11
11
  gem.add_dependency('json')
12
+ gem.add_dependency('rack')
13
+
14
+ gem.add_development_dependency('rake')
15
+ gem.add_development_dependency('rspec')
16
+ gem.add_development_dependency('oauth2')
12
17
 
13
18
  gem.files = `git ls-files`.split($\)
14
19
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
20
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
21
  gem.name = "assaydepot"
17
22
  gem.require_paths = ["lib"]
23
+
18
24
  gem.version = AssayDepot::VERSION
19
25
  end
data/lib/assaydepot.rb CHANGED
@@ -2,25 +2,22 @@ require "assaydepot/version"
2
2
  require "assaydepot/configurable"
3
3
  require "assaydepot/client"
4
4
  require "assaydepot/model"
5
- require "assaydepot/ware"
6
- require "assaydepot/provider"
7
-
8
- # Twitter.configure do |config|
9
- # config.consumer_key = YOUR_CONSUMER_KEY
10
- # config.consumer_secret = YOUR_CONSUMER_SECRET
11
- # config.oauth_token = YOUR_OAUTH_TOKEN
12
- # config.oauth_token_secret = YOUR_OAUTH_TOKEN_SECRET
13
- # end
5
+ require "assaydepot/core"
6
+ require "assaydepot/endpoints"
7
+ require "assaydepot/event"
14
8
 
15
9
  module AssayDepot
16
- class << self
17
- include AssayDepot::Configurable
10
+ class SignatureVerificationError < StandardError
11
+ def initialize(msg="Event not properly signed.", exception_type="custom")
12
+ @exception_type = exception_type
13
+ super(msg)
14
+ end
18
15
  end
19
16
 
20
- # Delegate to a AssayDepot::Client
21
- #
22
- # @return [AssayDepot::Client]
23
- def client
24
- AssayDepot::Client.new(options)
17
+ class WebhookError < StandardError
18
+ def initialize(msg="Webhook was not applied.", exception_type="custom")
19
+ @exception_type = exception_type
20
+ super(msg)
21
+ end
25
22
  end
26
- end
23
+ end
@@ -1,32 +1,95 @@
1
1
  require "open-uri"
2
2
  require "json"
3
+ require 'net/http'
4
+ require 'rack'
3
5
 
4
6
  module AssayDepot
5
- class Client
7
+ class Client
8
+
6
9
  def initialize(options={})
7
- @search_type = options[:search_type] || "wares"
10
+ @endpoint = options[:endpoint]
11
+ end
12
+
13
+ def request(url = nil, params={}, headers={}, auth={})
14
+ uri = url.nil? ? get_uri(params) : URI( "#{url}" )
15
+ puts "CLIENT.REQUEST HOST [#{uri.host}] URI [#{uri.request_uri}] PARAMS [#{params.inspect}]" if ENV["DEBUG"] == "true"
16
+ uri.query = Rack::Utils.build_nested_query(params) unless params.keys.length == 0
17
+ http = Net::HTTP.new(uri.host, uri.port)
18
+ http.use_ssl = uri.scheme === 'https'
19
+ request = Net::HTTP::Get.new(uri.request_uri)
20
+ request["Authorization"] = "Bearer #{AssayDepot.access_token}" unless params[:access_token] || auth[:username]
21
+ request.basic_auth auth[:username], auth[:password] unless auth[:username].nil?
22
+ res = http.request(request)
23
+ JSON.parse(res.body)
24
+ end
25
+
26
+ def get(params: {})
27
+ uri = get_uri( params )
28
+ http = Net::HTTP.new(uri.host, uri.port)
29
+ http.use_ssl = uri.scheme === 'https'
30
+ request = Net::HTTP::Get.new(uri.request_uri)
31
+ puts "CLIENT.GET HOST [#{uri.host}] URI [#{uri.request_uri}] PARAMS [#{params.inspect}]" if ENV["DEBUG"] == "true"
32
+ request["Authorization"] = "Bearer #{AssayDepot.access_token}" unless params[:access_token]
33
+ res = http.request(request)
34
+ res.body
8
35
  end
9
36
 
10
- def search_url(query, facets, params={})
11
- "#{AssayDepot.url}/#{@search_type}.json?#{params.collect { |k,v| "#{k}=#{v.to_s.gsub(" ","+")}"}.join("&")}"
37
+ def put(body: {}, params: {})
38
+ uri = get_uri( params )
39
+ http = Net::HTTP.new(uri.host, uri.port)
40
+ http.use_ssl = uri.scheme === 'https'
41
+ request = Net::HTTP::Put.new(uri.request_uri)
42
+ puts "CLIENT.PUT HOST [#{uri.host}] URI [#{uri.request_uri}] BODY [#{body.inspect}] PARAMS [#{params.inspect}]" if ENV["DEBUG"] == "true"
43
+ request["Authorization"] = "Bearer #{AssayDepot.access_token}" unless params[:access_token]
44
+ request["Content-Type"] = "application/json"
45
+ if (body.keys.length > 0)
46
+ request.body = body.to_json
47
+ end
48
+ res = http.request(request)
49
+ res.body
12
50
  end
13
51
 
14
- def get_url(id, params={})
15
- "#{AssayDepot.url}/#{@search_type}/#{id}.json?#{params.collect { |k,v| "#{k}=#{v.to_s.gsub(" ","+")}"}.join("&")}"
52
+ def post(body: {}, params: {})
53
+ uri = get_uri( params )
54
+ http = Net::HTTP.new(uri.host, uri.port)
55
+ http.use_ssl = uri.scheme === 'https'
56
+ request = Net::HTTP::Post.new(uri.request_uri)
57
+ puts "CLIENT.POST HOST [#{uri.host}] URI [#{uri.request_uri}] BODY [#{body.inspect}] PARAMS [#{params.inspect}]" if ENV["DEBUG"] == "true"
58
+ request["Authorization"] = "Bearer #{AssayDepot.access_token}" unless params[:access_token]
59
+ request["Accept"] = "application/json"
60
+ request["Content-Type"] = "application/json"
61
+ if (body && body.keys.length > 0)
62
+ request.body = body.to_json
63
+ end
64
+ res = http.request(request)
65
+ res.body
16
66
  end
17
67
 
18
- def search(query, facets, params={})
19
- params["auth_token"] = AssayDepot.auth_token
20
- params["q"] = query
21
- facets.map do |name,value|
68
+ def delete(params: {})
69
+ uri = get_uri( params )
70
+ http = Net::HTTP.new(uri.host, uri.port)
71
+ http.use_ssl = uri.scheme === 'https'
72
+ request = Net::HTTP::Delete.new(uri.request_uri)
73
+ puts "CLIENT.DELETE HOST [#{uri.host}] URI [#{uri.request_uri}]}] PARAMS [#{params.inspect}]" if ENV["DEBUG"] == "true"
74
+ request["Authorization"] = "Bearer #{AssayDepot.access_token}" unless params[:access_token]
75
+ res = http.request(request)
76
+ res.body
77
+ end
78
+
79
+ def search(query: nil, facets: {}, params: {})
80
+ params["q"] = query if query != ""
81
+ facets&.map do |name,value|
22
82
  params["facets[#{name}][]"] = value
23
83
  end
24
- JSON.parse(open(search_url(query, facets, params)).read)
84
+ get(params: params)
25
85
  end
26
86
 
27
- def get(id, params={})
28
- params["auth_token"] = AssayDepot.auth_token
29
- JSON.parse(open(get_url(id, params)).read)
87
+ private
88
+
89
+ def get_uri( params )
90
+ uri = URI( "#{AssayDepot.url}/#{@endpoint}" )
91
+ uri.query = Rack::Utils.build_nested_query(params) unless params.keys.length == 0
92
+ uri
30
93
  end
31
94
  end
32
- end
95
+ end
@@ -9,7 +9,7 @@ module AssayDepot
9
9
 
10
10
  CONFIG_KEYS = [
11
11
  :url,
12
- :auth_token,
12
+ :access_token,
13
13
  ] unless defined? CONFIG_KEYS
14
14
  attr_accessor *CONFIG_KEYS
15
15
 
@@ -0,0 +1,12 @@
1
+ module AssayDepot
2
+ class << self
3
+ include ::AssayDepot::Configurable
4
+ end
5
+
6
+ # Delegate to a AssayDepot::Client
7
+ #
8
+ # @return [AssayDepot::Client]
9
+ def client
10
+ ::AssayDepot::Client.new(options)
11
+ end
12
+ end
@@ -0,0 +1,236 @@
1
+ module AssayDepot
2
+
3
+ class Category
4
+ include ::AssayDepot::SearchModel
5
+
6
+ def self.endpoint(id=nil, format="json")
7
+ get_endpoint(id, "categories", format)
8
+ end
9
+
10
+ def self.ref_name
11
+ "category_refs"
12
+ end
13
+ end
14
+
15
+ class DynamicForm
16
+ include ::AssayDepot::SearchModel
17
+
18
+ def self.endpoint(id=nil, format="json")
19
+ get_endpoint(id, "dynamic_forms", format)
20
+ end
21
+ end
22
+
23
+ class Info
24
+ include ::AssayDepot::SearchModel
25
+
26
+ def self.endpoint(id=nil, format="json")
27
+ get_endpoint(nil, "info", format)
28
+ end
29
+ end
30
+
31
+ class Organization
32
+ include ::AssayDepot::SearchModel
33
+
34
+ def self.endpoint(id=nil, format="json")
35
+ get_endpoint(id, "organizations", format)
36
+ end
37
+ end
38
+
39
+ class QuoteGroup
40
+ include ::AssayDepot::SearchModel
41
+
42
+ def self.mine
43
+ get(id: "mine")
44
+ end
45
+
46
+ def self.endpoint(id=nil, format="json")
47
+ get_endpoint(id, "quote_groups", format)
48
+ end
49
+
50
+ def self.ref_name
51
+ "quote_group_refs"
52
+ end
53
+ end
54
+
55
+ class AddNote
56
+ include ::AssayDepot::SearchModel
57
+
58
+ def self.endpoint(id, format="json")
59
+ "/quote_groups/#{id}/add_note.#{format}"
60
+ end
61
+
62
+ def self.ref_name
63
+ "quote_group_refs"
64
+ end
65
+ end
66
+
67
+ class QuotedWare
68
+ include ::AssayDepot::SearchModel
69
+
70
+ def self.proposals(id, format="json")
71
+ get(id: "#{id[:id]}/proposals", format: format)
72
+ end
73
+
74
+ def self.purchase_orders(id, format="json")
75
+ get(id: "#{id[:id]}/purchase_orders", format: format)
76
+ end
77
+
78
+ def self.messages(id, format="json")
79
+ get(id: "#{id[:id]}/messages", format: format)
80
+ end
81
+
82
+ def self.endpoint(id=nil, format="json")
83
+ get_endpoint(id, "quoted_wares", format)
84
+ end
85
+
86
+ def self.ref_name
87
+ "quoted_ware_refs"
88
+ end
89
+ end
90
+
91
+ class Provider
92
+ include ::AssayDepot::SearchModel
93
+
94
+ def self.endpoint(id=nil, format="json")
95
+ get_endpoint( id, "providers", format)
96
+ end
97
+
98
+ def self.search_type
99
+ "providers"
100
+ end
101
+
102
+ def self.ref_name
103
+ "provider_refs"
104
+ end
105
+ end
106
+
107
+ class ProviderWare
108
+ include ::AssayDepot::SearchModel
109
+
110
+ def self.endpoint(id, format="json")
111
+ "/providers/#{id.is_a?(Array) ? id[0] : id}/wares.#{format}"
112
+ end
113
+
114
+ def self.ref_name
115
+ "ware_refs"
116
+ end
117
+ end
118
+
119
+ class User
120
+ include ::AssayDepot::SearchModel
121
+
122
+ def self.profile
123
+ get(id: "profile")
124
+ end
125
+
126
+ def self.endpoint(id=nil, format="json")
127
+ get_endpoint(id == nil || id[0] == nil ? nil : 'profile', "users", format)
128
+ end
129
+
130
+ def self.ref_name
131
+ "user_refs"
132
+ end
133
+ end
134
+
135
+ class Ware
136
+ include ::AssayDepot::SearchModel
137
+
138
+ def self.endpoint(id=nil, format="json")
139
+ get_endpoint( id, "wares", format)
140
+ end
141
+
142
+ def self.search_type
143
+ "wares"
144
+ end
145
+
146
+ def self.ref_name
147
+ "ware_refs"
148
+ end
149
+ end
150
+
151
+ class WareProvider
152
+ include ::AssayDepot::SearchModel
153
+
154
+ def self.endpoint(id, format="json")
155
+ if (id.is_a?(Array) && id.length > 1)
156
+ url = "/wares/#{id[0]}/providers/#{id[1]}.#{format}"
157
+ else
158
+ url = "/wares/#{id.is_a?(Array) ? id[0] : id}/providers.#{format}"
159
+ end
160
+ url
161
+ end
162
+
163
+ def self.ref_name
164
+ "provider_refs"
165
+ end
166
+ end
167
+
168
+ class Webhook
169
+ include ::AssayDepot::SearchModel
170
+
171
+ def self.endpoint(id=nil, format="json")
172
+ get_endpoint(id, "webhook_config", format)
173
+ end
174
+
175
+ def self.ref_name
176
+ "results"
177
+ end
178
+ end
179
+
180
+ class TokenAuth
181
+ include ::AssayDepot::SearchModel
182
+
183
+ def self.endpoint(site="", format=nil)
184
+ "#{site}/oauth/token?grant_type=client_credentials"
185
+ end
186
+
187
+ def self.ref_name
188
+ "access_token"
189
+ end
190
+ end
191
+
192
+ class PurchaseOrder
193
+ include ::AssayDepot::DatabaseModel
194
+
195
+ def self.endpoint(id=nil, format="json")
196
+ get_endpoint(id, "purchase_orders", format)
197
+ end
198
+
199
+ def self.ref_name
200
+ "purchase_orders"
201
+ end
202
+ end
203
+
204
+ class List
205
+ include ::AssayDepot::DatabaseModel
206
+
207
+ def self.create(slug, name)
208
+ post(body: { slug: slug, name: name })
209
+ end
210
+
211
+ def self.endpoint(id=nil, format="json")
212
+ get_endpoint(id, "dynamic_lists", format)
213
+ end
214
+
215
+ def self.ref_name
216
+ "dynamic_lists"
217
+ end
218
+ end
219
+
220
+ class ListItem
221
+ include ::AssayDepot::SearchModel
222
+
223
+ def self.endpoint(id, format="json")
224
+ if (id.is_a?(Array) && id.length > 1)
225
+ url = "/dynamic_lists/#{id[0]}/items/#{id[1]}.#{format}"
226
+ else
227
+ url = "/dynamic_lists/#{id.is_a?(Array) ? id[0] : id}/items.#{format}"
228
+ end
229
+ url
230
+ end
231
+
232
+ def self.ref_name
233
+ "items"
234
+ end
235
+ end
236
+ end