assaydepot 0.0.5 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: aa533354a0d547e58f3126a353a07aa5addb768a
4
- data.tar.gz: 6b96d17cdf3d767ecff0abda1b4059c394b223e3
2
+ SHA256:
3
+ metadata.gz: ac3e59291589c598212136d3054ea0c5abc24c594b7278f3ab69b28c25fa7509
4
+ data.tar.gz: 3cabe89cd8cd5c7828a6de608ccf5587867ab707bbda355900b6cd9830c50528
5
5
  SHA512:
6
- metadata.gz: c674589b7d71bc9ffb11cfd8a13d798502c08fe06656044fb9909d66a86f27729a4745e10a060d9c5fb14690d213035cd74bb85fc0ab5da507bfd7f96621dee5
7
- data.tar.gz: 899c7ea6a6bbce87b2cc3c16e5ab1c89a701c5ed85d7754ba03f660ef902e197489c4213925aaca48af6ca464545a9e77eac6c55a92e7e3aa3585d40ccb1351c
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
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format documentation
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
  gem 'pry'
3
3
  gem 'pry-byebug'
4
- gem 'uri-query_params'
5
4
  gem 'dotenv-rails', groups: [:development, :test]
6
5
 
7
6
  # Specify your gem's dependencies in assaydepot.gemspec
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # Assay Depot ![Build Status](https://secure.travis-ci.org/assaydepot/assaydepot-rb.png) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/assaydepot/assaydepot-rb)
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
4
 
5
- ## Assay Depot Developer Program
5
+ ## Scientist.com Developer Program
6
6
 
7
- An authentication token is required for the API to function. If you would like access to the API, please email cpetersen@assaydepot.com.
7
+ An authentication token is required for the API to function. If you would like access to the API, please email support@scientist.com.
8
8
 
9
9
  ## Installation
10
10
 
@@ -22,16 +22,32 @@ Or install it yourself as:
22
22
 
23
23
  ## Basic Usage
24
24
 
25
+ ### Storefront
26
+
25
27
  ```ruby
26
28
  require 'assaydepot'
27
29
  AssayDepot.configure do |config|
28
30
  config.access_token = "1234567890"
29
- config.url = "https://www.assaydepot.com/api"
31
+ config.url = "https://app.scientist.com"
30
32
  end
31
33
  wares = AssayDepot::Ware.find("Antibody")
32
34
  wares.total
33
35
  ```
34
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
+
35
51
  ## Using Facets
36
52
 
37
53
  ```ruby
@@ -56,7 +72,7 @@ providers.count
56
72
  ## Get Details
57
73
  ```ruby
58
74
  providers = AssayDepot::Provider.where(:starts_with => "a")
59
- AssayDepot::Provider.get(providers.first["id"])
75
+ AssayDepot::Provider.get(id: providers.first["id"])
60
76
  ```
61
77
 
62
78
  ## Contributing
@@ -69,4 +85,4 @@ AssayDepot::Provider.get(providers.first["id"])
69
85
 
70
86
  ## License
71
87
 
72
- The Assay Depot Ruby SDK is released under the MIT license.
88
+ The Scientist.com Ruby SDK is released under the MIT license.
data/assaydepot.gemspec CHANGED
@@ -2,14 +2,14 @@
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('uri-query_params')
12
+ gem.add_dependency('rack')
13
13
 
14
14
  gem.add_development_dependency('rake')
15
15
  gem.add_development_dependency('rspec')
@@ -1,7 +1,7 @@
1
1
  require "open-uri"
2
2
  require "json"
3
- require 'uri/query_params'
4
3
  require 'net/http'
4
+ require 'rack'
5
5
 
6
6
  module AssayDepot
7
7
  class Client
@@ -10,75 +10,86 @@ module AssayDepot
10
10
  @endpoint = options[:endpoint]
11
11
  end
12
12
 
13
- def request(url, params={}, headers={}, auth={})
14
- uri = URI( "#{url}" )
15
- uri.query = URI.encode_www_form( params ) unless params.keys.length == 0
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
16
17
  http = Net::HTTP.new(uri.host, uri.port)
18
+ http.use_ssl = uri.scheme === 'https'
17
19
  request = Net::HTTP::Get.new(uri.request_uri)
20
+ request["Authorization"] = "Bearer #{AssayDepot.access_token}" unless params[:access_token] || auth[:username]
18
21
  request.basic_auth auth[:username], auth[:password] unless auth[:username].nil?
19
22
  res = http.request(request)
20
23
  JSON.parse(res.body)
21
24
  end
22
25
 
23
- def get(params={})
26
+ def get(params: {})
24
27
  uri = get_uri( params )
25
28
  http = Net::HTTP.new(uri.host, uri.port)
29
+ http.use_ssl = uri.scheme === 'https'
26
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"
27
32
  request["Authorization"] = "Bearer #{AssayDepot.access_token}" unless params[:access_token]
28
33
  res = http.request(request)
29
- JSON.parse(res.body)
34
+ res.body
30
35
  end
31
36
 
32
- def put(body={}, params={})
37
+ def put(body: {}, params: {})
33
38
  uri = get_uri( params )
34
39
  http = Net::HTTP.new(uri.host, uri.port)
40
+ http.use_ssl = uri.scheme === 'https'
35
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"
36
43
  request["Authorization"] = "Bearer #{AssayDepot.access_token}" unless params[:access_token]
37
44
  request["Content-Type"] = "application/json"
38
45
  if (body.keys.length > 0)
39
46
  request.body = body.to_json
40
47
  end
41
48
  res = http.request(request)
42
- JSON.parse(res.body)
49
+ res.body
43
50
  end
44
51
 
45
- def post(body={}, params={})
52
+ def post(body: {}, params: {})
46
53
  uri = get_uri( params )
47
54
  http = Net::HTTP.new(uri.host, uri.port)
55
+ http.use_ssl = uri.scheme === 'https'
48
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"
49
58
  request["Authorization"] = "Bearer #{AssayDepot.access_token}" unless params[:access_token]
50
59
  request["Accept"] = "application/json"
51
60
  request["Content-Type"] = "application/json"
52
- if (body.keys.length > 0)
61
+ if (body && body.keys.length > 0)
53
62
  request.body = body.to_json
54
63
  end
55
64
  res = http.request(request)
56
- JSON.parse(res.body)
65
+ res.body
57
66
  end
58
67
 
59
- def delete(params={})
68
+ def delete(params: {})
60
69
  uri = get_uri( params )
61
70
  http = Net::HTTP.new(uri.host, uri.port)
71
+ http.use_ssl = uri.scheme === 'https'
62
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"
63
74
  request["Authorization"] = "Bearer #{AssayDepot.access_token}" unless params[:access_token]
64
75
  res = http.request(request)
65
- JSON.parse(res.body)
76
+ res.body
66
77
  end
67
78
 
68
- def search(query, facets, params={})
79
+ def search(query: nil, facets: {}, params: {})
69
80
  params["q"] = query if query != ""
70
- facets.map do |name,value|
81
+ facets&.map do |name,value|
71
82
  params["facets[#{name}][]"] = value
72
83
  end
73
- get(params)
84
+ get(params: params)
74
85
  end
75
86
 
76
87
  private
77
88
 
78
89
  def get_uri( params )
79
90
  uri = URI( "#{AssayDepot.url}/#{@endpoint}" )
80
- uri.query = URI.encode_www_form( params ) unless params.keys.length == 0
91
+ uri.query = Rack::Utils.build_nested_query(params) unless params.keys.length == 0
81
92
  uri
82
93
  end
83
94
  end
84
- end
95
+ end
@@ -1,10 +1,10 @@
1
1
  module AssayDepot
2
2
 
3
3
  class Category
4
- include ::AssayDepot::Model
4
+ include ::AssayDepot::SearchModel
5
5
 
6
- def self.endpoint(id=nil)
7
- get_endpoint(id, "categories")
6
+ def self.endpoint(id=nil, format="json")
7
+ get_endpoint(id, "categories", format)
8
8
  end
9
9
 
10
10
  def self.ref_name
@@ -13,34 +13,38 @@ module AssayDepot
13
13
  end
14
14
 
15
15
  class DynamicForm
16
- include ::AssayDepot::Model
16
+ include ::AssayDepot::SearchModel
17
17
 
18
- def self.endpoint(id=nil)
19
- get_endpoint(id, "dynamic_forms")
18
+ def self.endpoint(id=nil, format="json")
19
+ get_endpoint(id, "dynamic_forms", format)
20
20
  end
21
21
  end
22
22
 
23
23
  class Info
24
- include ::AssayDepot::Model
24
+ include ::AssayDepot::SearchModel
25
25
 
26
- def self.endpoint(id=nil)
27
- get_endpoint(nil, "info")
26
+ def self.endpoint(id=nil, format="json")
27
+ get_endpoint(nil, "info", format)
28
28
  end
29
29
  end
30
30
 
31
31
  class Organization
32
- include ::AssayDepot::Model
32
+ include ::AssayDepot::SearchModel
33
33
 
34
- def self.endpoint(id=nil)
35
- get_endpoint(id, "organizations")
34
+ def self.endpoint(id=nil, format="json")
35
+ get_endpoint(id, "organizations", format)
36
36
  end
37
37
  end
38
38
 
39
39
  class QuoteGroup
40
- include ::AssayDepot::Model
40
+ include ::AssayDepot::SearchModel
41
41
 
42
- def self.endpoint(id=nil)
43
- get_endpoint(id, "quote_groups")
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)
44
48
  end
45
49
 
46
50
  def self.ref_name
@@ -49,10 +53,10 @@ module AssayDepot
49
53
  end
50
54
 
51
55
  class AddNote
52
- include ::AssayDepot::Model
56
+ include ::AssayDepot::SearchModel
53
57
 
54
- def self.endpoint(id)
55
- "/quote_groups/#{id}/add_note"
58
+ def self.endpoint(id, format="json")
59
+ "/quote_groups/#{id}/add_note.#{format}"
56
60
  end
57
61
 
58
62
  def self.ref_name
@@ -61,10 +65,22 @@ module AssayDepot
61
65
  end
62
66
 
63
67
  class QuotedWare
64
- include ::AssayDepot::Model
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
65
81
 
66
- def self.endpoint(id=nil)
67
- get_endpoint(id, "quoted_wares")
82
+ def self.endpoint(id=nil, format="json")
83
+ get_endpoint(id, "quoted_wares", format)
68
84
  end
69
85
 
70
86
  def self.ref_name
@@ -73,10 +89,10 @@ module AssayDepot
73
89
  end
74
90
 
75
91
  class Provider
76
- include ::AssayDepot::Model
92
+ include ::AssayDepot::SearchModel
77
93
 
78
- def self.endpoint(id=nil)
79
- get_endpoint( id, "providers" )
94
+ def self.endpoint(id=nil, format="json")
95
+ get_endpoint( id, "providers", format)
80
96
  end
81
97
 
82
98
  def self.search_type
@@ -89,10 +105,10 @@ module AssayDepot
89
105
  end
90
106
 
91
107
  class ProviderWare
92
- include ::AssayDepot::Model
108
+ include ::AssayDepot::SearchModel
93
109
 
94
- def self.endpoint(id)
95
- "/providers/#{id.is_a?(Array) ? id[0] : id}/wares.json"
110
+ def self.endpoint(id, format="json")
111
+ "/providers/#{id.is_a?(Array) ? id[0] : id}/wares.#{format}"
96
112
  end
97
113
 
98
114
  def self.ref_name
@@ -101,10 +117,14 @@ module AssayDepot
101
117
  end
102
118
 
103
119
  class User
104
- include ::AssayDepot::Model
120
+ include ::AssayDepot::SearchModel
121
+
122
+ def self.profile
123
+ get(id: "profile")
124
+ end
105
125
 
106
- def self.endpoint(id=nil)
107
- get_endpoint(id == nil || id[0] == nil ? nil : 'profile', "users")
126
+ def self.endpoint(id=nil, format="json")
127
+ get_endpoint(id == nil || id[0] == nil ? nil : 'profile', "users", format)
108
128
  end
109
129
 
110
130
  def self.ref_name
@@ -113,10 +133,10 @@ module AssayDepot
113
133
  end
114
134
 
115
135
  class Ware
116
- include ::AssayDepot::Model
136
+ include ::AssayDepot::SearchModel
117
137
 
118
- def self.endpoint(id=nil)
119
- get_endpoint( id, "wares" )
138
+ def self.endpoint(id=nil, format="json")
139
+ get_endpoint( id, "wares", format)
120
140
  end
121
141
 
122
142
  def self.search_type
@@ -129,13 +149,13 @@ module AssayDepot
129
149
  end
130
150
 
131
151
  class WareProvider
132
- include ::AssayDepot::Model
152
+ include ::AssayDepot::SearchModel
133
153
 
134
- def self.endpoint(id)
154
+ def self.endpoint(id, format="json")
135
155
  if (id.is_a?(Array) && id.length > 1)
136
- url = "/wares/#{id[0]}/providers/#{id[1]}.json"
156
+ url = "/wares/#{id[0]}/providers/#{id[1]}.#{format}"
137
157
  else
138
- url = "/wares/#{id.is_a?(Array) ? id[0] : id}/providers.json"
158
+ url = "/wares/#{id.is_a?(Array) ? id[0] : id}/providers.#{format}"
139
159
  end
140
160
  url
141
161
  end
@@ -146,10 +166,10 @@ module AssayDepot
146
166
  end
147
167
 
148
168
  class Webhook
149
- include ::AssayDepot::Model
169
+ include ::AssayDepot::SearchModel
150
170
 
151
- def self.endpoint(id=nil)
152
- get_endpoint(id, "webhook_config")
171
+ def self.endpoint(id=nil, format="json")
172
+ get_endpoint(id, "webhook_config", format)
153
173
  end
154
174
 
155
175
  def self.ref_name
@@ -158,9 +178,9 @@ module AssayDepot
158
178
  end
159
179
 
160
180
  class TokenAuth
161
- include ::AssayDepot::Model
181
+ include ::AssayDepot::SearchModel
162
182
 
163
- def self.endpoint(site="")
183
+ def self.endpoint(site="", format=nil)
164
184
  "#{site}/oauth/token?grant_type=client_credentials"
165
185
  end
166
186
 
@@ -168,4 +188,49 @@ module AssayDepot
168
188
  "access_token"
169
189
  end
170
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
171
236
  end
@@ -1,18 +1,35 @@
1
1
  require 'forwardable'
2
2
  module AssayDepot
3
- module Model
3
+ module DatabaseModel
4
4
  module ClassMethods
5
-
6
- def get_token(client_id, client_secret, site)
7
- response = Client.new.request(AssayDepot::TokenAuth.endpoint(site), {}, {}, {:username => client_id, :password => client_secret})
8
- response[AssayDepot::TokenAuth.ref_name]
5
+ def all(options = {})
6
+ self.new.all(options)
9
7
  end
8
+ end
10
9
 
11
- def get_endpoint( id, endpoint )
12
- id = id[0] if id && id.kind_of?(Array)
13
- id ? "#{endpoint}/#{id}.json" : "#{endpoint}.json"
10
+ def self.included(base)
11
+ base.include AssayDepot::Model
12
+ base.extend AssayDepot::Model::ClassMethods
13
+ base.extend ClassMethods
14
+ end
15
+
16
+ def all(options = {})
17
+ result = self.clone
18
+ result.internal_options = options
19
+ result
20
+ end
21
+
22
+ # Overridden from Model
23
+ def internal_results
24
+ unless @internal_results
25
+ @internal_results = JSON.parse(Client.new(endpoint: self.class.endpoint(nil)).get(params: @internal_options))
14
26
  end
27
+ @internal_results
28
+ end
29
+ end
15
30
 
31
+ module SearchModel
32
+ module ClassMethods
16
33
  # find and where to modify params
17
34
  def find(query)
18
35
  self.new.find(query)
@@ -21,55 +38,97 @@ module AssayDepot
21
38
  def where(conditions={})
22
39
  self.new.where(conditions)
23
40
  end
41
+ end
24
42
 
25
- # HTTP request verbs
26
- # optional "id" followed by optional hash
27
- def get(*id, **params)
28
- Client.new(:endpoint => endpoint(id)).get(params)
43
+ def self.included(base)
44
+ base.extend AssayDepot::Model::ClassMethods
45
+ base.extend ClassMethods
46
+ base.include AssayDepot::Model
47
+ base.include AssayDepot::Pageable
48
+
49
+ attr_accessor :search_query
50
+ attr_accessor :search_facets
51
+ end
52
+
53
+ def initialize(options={})
54
+ @internal_options = options[:search_options] || { }
55
+ @search_query = options[:search_query] || ""
56
+ @search_facets = options[:search_facets] || { }
57
+ end
58
+
59
+ def facets
60
+ internal_results["facets"]
61
+ end
62
+
63
+ def find(query)
64
+ result = self.clone
65
+ result.search_query = query
66
+ result
67
+ end
68
+
69
+ def where(conditions={})
70
+ result = self.clone
71
+ result.search_facets = self.search_facets ? self.search_facets.merge(conditions) : conditions
72
+ result
73
+ end
74
+
75
+ # Overridden from Model
76
+ def internal_results
77
+ unless @internal_results
78
+ results = Client.new(endpoint: self.class.endpoint(nil)).search(query: search_query, facets: search_facets, params: internal_options)
79
+ @internal_results = JSON.parse(results)
80
+ end
81
+ @internal_results
82
+ end
83
+ end
84
+
85
+ module Model
86
+ module ClassMethods
87
+ def get_token(client_id, client_secret, site)
88
+ response = Client.new.request(AssayDepot::TokenAuth.endpoint(site), {}, {}, {:username => client_id, :password => client_secret})
89
+ response[AssayDepot::TokenAuth.ref_name]
29
90
  end
30
91
 
31
- def put(*id, **params)
92
+ def get_endpoint(id, endpoint, format = "json")
93
+ id = id[0] if id && id.kind_of?(Array)
94
+ id ? "#{endpoint}/#{id}.#{format}" : "#{endpoint}.#{format}"
95
+ end
32
96
 
33
- id, body, params = get_variable_args(id, params)
34
- # puts "id #{id}, body #{body.to_s}, params #{params}"
35
- Client.new(:endpoint => endpoint(id)).put( body, params )
97
+ # HTTP request verbs
98
+ # optional "id" followed by optional hash
99
+ def get(id: nil, params: {}, format: "json")
100
+ puts "GET id #{id}, params #{params}" if ENV["DEBUG"] == "true"
101
+ result = Client.new(endpoint: endpoint(id, format)).get(params: params)
102
+ return JSON.parse(result) if format == "json"
103
+ result
36
104
  end
37
105
 
38
- def patch(*id, **params)
39
- id, body, params = get_variable_args(id, params)
40
- Client.new(:endpoint => endpoint(id)).put( body, params )
106
+ def put(id: nil, body: nil, params: {}, format: "json")
107
+ puts "PUT id #{id}, body #{body.to_s}, params #{params}" if ENV["DEBUG"] == "true"
108
+ result = Client.new(endpoint: endpoint(id, format)).put( body: body, params: params )
109
+ return JSON.parse(result) if format == "json"
110
+ result
41
111
  end
42
112
 
43
- def post(*id, **params)
44
- id, body, params = get_variable_args(id, params)
45
- Client.new(:endpoint => endpoint(id)).post( body, params )
113
+ def patch(id: nil, body: nil, params: {}, format: "json")
114
+ puts "PATCH id #{id}, body #{body.to_s}, params #{params}" if ENV["DEBUG"] == "true"
115
+ result = Client.new(endpoint: endpoint(id, format)).put( body: body, params: params )
116
+ return JSON.parse(result) if format == "json"
117
+ result
46
118
  end
47
119
 
48
- def delete(*id, **params)
49
- Client.new(:endpoint => endpoint(id)).delete(params)
120
+ def post(id: nil, body: nil, params: {}, format: "json")
121
+ puts "POST id #{id}, body #{body.to_s}, params #{params}" if ENV["DEBUG"] == "true"
122
+ result = Client.new(endpoint: endpoint(id, format)).post( body: body, params: params )
123
+ return JSON.parse(result) if format == "json"
124
+ result
50
125
  end
51
126
 
52
- def get_variable_args(id, params)
53
-
54
- if (id && id.length > 1 && (id[1].is_a?(Integer) || id[1].is_a?(String)))
55
- body = params
56
- params = {}
57
- elsif (id && id.length > 1)
58
- body = id[1]
59
- id = id[0]
60
- elsif (id && id[0].is_a?(Hash))
61
- body = id.last
62
- id = nil
63
- elsif (id && id.length == 1 && id[0].is_a?(Hash) == false)
64
- body = params
65
- id = id[0]
66
- params = {}
67
- else
68
- body = params
69
- params = {}
70
- id = nil
71
- end
72
- [id, body, params]
127
+ def delete(id: nil, body: nil, params: {}, format: "json")
128
+ puts "DELETE id #{id}, params #{params}" if ENV["DEBUG"] == "true"
129
+ result = Client.new(endpoint: endpoint(id, format)).delete(params: params)
130
+ return JSON.parse(result) if format == "json"
131
+ result
73
132
  end
74
133
  end
75
134
 
@@ -98,73 +157,58 @@ module AssayDepot
98
157
  :reject,
99
158
  :reverse
100
159
 
101
- attr_accessor :search_query
102
- attr_accessor :search_facets
103
- attr_accessor :search_options
160
+ attr_accessor :internal_options
161
+ end
104
162
 
105
- def initialize(options={})
106
- @search_query = options[:search_query] || ""
107
- @search_facets = options[:search_facets] || {}
108
- @search_options = options[:search_options] || {:page => 1}
109
- end
163
+ def initialize(options={})
164
+ @internal_options = options[:search_options] || { }
165
+ end
110
166
 
111
- def initialize_copy(source)
112
- super
113
- @search_query = @search_query.dup
114
- @search_facets = @search_facets.dup
115
- end
167
+ def initialize_copy(source)
168
+ super
169
+ @search_query = @search_query.dup
170
+ @search_facets = @search_facets.dup
171
+ end
116
172
 
117
- def query_time
118
- search_results["query_time"]
119
- end
120
- def total
121
- search_results["total"]
122
- end
123
- def page
124
- search_results["page"]
125
- end
126
- def per_page
127
- search_results["per_page"]
128
- end
129
- def facets
130
- search_results["facets"]
131
- end
173
+ def query_time
174
+ internal_results["query_time"]
175
+ end
132
176
 
133
- def page(page_num)
134
- options( { "page" => page_num } )
135
- end
177
+ def total
178
+ internal_results["total"]
179
+ end
136
180
 
137
- def per_page(page_size)
138
- options( { "per_page" => page_size } )
139
- end
181
+ def options(options={})
182
+ result = self.clone
183
+ result.internal_options = self.internal_options ? self.internal_options.merge(options) : options
184
+ result
185
+ end
140
186
 
141
- def find(query)
142
- result = self.clone
143
- result.search_query = query
144
- result
145
- end
187
+ def private_results
188
+ internal_results[self.class.ref_name]
189
+ end
146
190
 
147
- def where(conditions={})
148
- result = self.clone
149
- result.search_facets = self.search_facets ? self.search_facets.merge(conditions) : conditions
150
- result
151
- end
191
+ # def internal_results
192
+ # # To be overridden
193
+ # # If I leave this method in, it gets called, possibly a problem with the order of inclusion
194
+ # end
195
+ end
152
196
 
153
- def options(options={})
154
- result = self.clone
155
- result.search_options = self.search_options ? self.search_options.merge(options) : options
156
- result
157
- end
197
+ module Pageable
198
+ def page
199
+ internal_results["page"]
200
+ end
158
201
 
159
- def private_results
160
- search_results[self.class.ref_name]
161
- end
162
- def search_results
163
- unless @search_results
164
- @search_results = Client.new(:endpoint => self.class.endpoint(nil)).search(search_query, search_facets, search_options)
165
- end
166
- @search_results
167
- end
202
+ def per_page
203
+ internal_results["per_page"]
204
+ end
205
+
206
+ def page(page_num)
207
+ options( { "page" => page_num } )
208
+ end
209
+
210
+ def per_page(page_size)
211
+ options( { "per_page" => page_size } )
168
212
  end
169
213
  end
170
214
  end
@@ -1,3 +1,3 @@
1
1
  module AssayDepot
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,30 @@
1
+ require 'assaydepot'
2
+ require 'dotenv'
3
+ Dotenv.load
4
+
5
+ describe AssayDepot do
6
+ context "scientist_api backoffice tests" do
7
+ before(:all) do
8
+ AssayDepot.configure do |config|
9
+ config.access_token = ENV['BACKOFFICE_ACCESS_TOKEN']
10
+ config.url = "#{ENV['BACKOFFICE_SITE']}/api/v2"
11
+ end
12
+ end
13
+
14
+ context "info" do
15
+ let(:info) { AssayDepot::Info.get() }
16
+
17
+ it "info version V2" do
18
+ info["api_version"].should == "V2"
19
+ end
20
+ end
21
+
22
+ context "quoted wares" do
23
+ let(:qw) { AssayDepot::QuotedWare.get() }
24
+
25
+ it "get all quoted wares" do
26
+ qw.is_a?(Array).should == true
27
+ end
28
+ end
29
+ end
30
+ end
@@ -5,10 +5,9 @@ Dotenv.load
5
5
  describe AssayDepot do
6
6
  context "when accessing the api via token client credentials" do
7
7
  before(:all) do
8
- site = "http://dev.scientist.com:3000"
9
8
  AssayDepot.configure do |config|
10
9
  config.access_token = ENV['ACCESS_TOKEN']
11
- config.url = "#{site}/api/v2"
10
+ config.url = "#{ENV['SITE']}/api/v2"
12
11
  end
13
12
  end
14
13
 
@@ -24,7 +23,7 @@ describe AssayDepot do
24
23
  end
25
24
 
26
25
  context "and getting the details for the first ware" do
27
- let(:ware_result) { AssayDepot::Ware.get(wares.first["id"]) }
26
+ let(:ware_result) { AssayDepot::Ware.get(id: wares.first["id"]) }
28
27
 
29
28
  it "should have a ware" do
30
29
  ware_result["ware"].should_not be_nil
@@ -110,14 +109,14 @@ describe AssayDepot do
110
109
  end
111
110
 
112
111
  context "and getting the details for the first provider" do
113
- let(:provider_result) { AssayDepot::Provider.get(providers.first["id"]) }
112
+ let(:provider_result) { AssayDepot::Provider.get(id: providers.first["id"]) }
114
113
 
115
- it "should have a provider" do
114
+ it "have a provider" do
116
115
  provider_result["provider"].should_not be_nil
117
116
  end
118
117
 
119
- it "should have a description" do
120
- provider_result["provider"]["description"].should_not be_nil
118
+ it "have keywords" do
119
+ expect(provider_result['provider']).to have_key('keywords')
121
120
  end
122
121
  end
123
122
  end
@@ -5,10 +5,9 @@ Dotenv.load
5
5
  describe AssayDepot do
6
6
  context "scientist_api tests" do
7
7
  before(:all) do
8
- site = "http://dev.scientist.com:3000"
9
8
  AssayDepot.configure do |config|
10
9
  config.access_token = ENV['ACCESS_TOKEN']
11
- config.url = "#{site}/api/v2"
10
+ config.url = "#{ENV['SITE']}/api/v2"
12
11
  end
13
12
  end
14
13
 
@@ -27,7 +26,7 @@ describe AssayDepot do
27
26
  end
28
27
 
29
28
  it "get specific category" do
30
- category = AssayDepot::Category.get(categories[AssayDepot::Category.ref_name].first[:id])
29
+ category = AssayDepot::Category.get(id: categories[AssayDepot::Category.ref_name].first[:id])
31
30
  categories[AssayDepot::Category.ref_name][0][:id].should == category[:id]
32
31
  end
33
32
  end
@@ -40,7 +39,7 @@ describe AssayDepot do
40
39
  end
41
40
 
42
41
  it "get specific organization" do
43
- organization = AssayDepot::Organization.get(organizations.first["id"])
42
+ organization = AssayDepot::Organization.get(id: organizations.first["id"])
44
43
  organizations.first["id"].should == organization["id"]
45
44
  end
46
45
  end
@@ -54,28 +53,28 @@ describe AssayDepot do
54
53
 
55
54
  it "get specific provider" do
56
55
  id = providers[AssayDepot::Provider.ref_name].first["id"]
57
- provider = AssayDepot::Provider.get(id)
56
+ provider = AssayDepot::Provider.get(id: id)
58
57
  id.is_a?(Integer).should == true
59
58
  id.should == provider["provider"]["id"]
60
59
  end
61
60
 
62
61
  it "get wares for a specific provider" do
63
62
  id = providers[AssayDepot::Provider.ref_name].first["id"]
64
- ware = AssayDepot::ProviderWare.get(id)
63
+ ware = AssayDepot::ProviderWare.get(id: id)
65
64
  ware[AssayDepot::ProviderWare.ref_name].is_a?(Array).should == true
66
65
  end
67
66
 
68
67
  it "update specific provider attribute" do
69
68
  id = providers[AssayDepot::Provider.ref_name].first["id"]
70
69
  num_employees = rand(1000)
71
- response = AssayDepot::Provider.put(id, {number_of_employees: num_employees});
70
+ response = AssayDepot::Provider.put(id: id, body: { number_of_employees: num_employees });
72
71
  response["code"].should == "forbidden"
73
72
  end
74
73
 
75
74
  end
76
75
 
77
76
  context "quote groups" do
78
- let(:qg) { AssayDepot::QuoteGroup.get('mine')}
77
+ let(:qg) { AssayDepot::QuoteGroup.mine }
79
78
 
80
79
  it "quote groups mine" do
81
80
  qg[AssayDepot::QuoteGroup.ref_name].is_a?(Array).should == true
@@ -83,7 +82,7 @@ describe AssayDepot do
83
82
 
84
83
  it "quote groups specific id" do
85
84
  id = qg[AssayDepot::QuoteGroup.ref_name].first["id"]
86
- response = AssayDepot::QuoteGroup.get( id )
85
+ response = AssayDepot::QuoteGroup.get( id: id )
87
86
  response["id"].should == id
88
87
  end
89
88
 
@@ -91,7 +90,7 @@ describe AssayDepot do
91
90
  id = qg[AssayDepot::QuoteGroup.ref_name].first["id"]
92
91
  title_text = "This is some #{rand(1000)} text."
93
92
  body_text = "This is some #{rand(1000)} body text."
94
- response = AssayDepot::AddNote.post(id, {
93
+ response = AssayDepot::AddNote.post(id: id, body: {
95
94
  note: {
96
95
  title: title_text,
97
96
  body: body_text
@@ -101,17 +100,9 @@ describe AssayDepot do
101
100
  end
102
101
  end
103
102
 
104
- context "quoted wares" do
105
- let(:qw) { AssayDepot::QuotedWare.get() }
106
-
107
- it "get all quoted wares" do
108
- qw.is_a?(Array).should == true
109
- end
110
- end
111
-
112
103
  context "users" do
113
104
  let(:users) { AssayDepot::User.get() }
114
- let(:profile) { AssayDepot::User.get('profile') }
105
+ let(:profile) { AssayDepot::User.profile }
115
106
 
116
107
  it "get all users" do
117
108
  users[AssayDepot::User.ref_name].is_a?(Array).should == true
@@ -130,12 +121,12 @@ describe AssayDepot do
130
121
  end
131
122
 
132
123
  it "get specific ware" do
133
- ware = AssayDepot::Ware.get( wares[AssayDepot::Ware.ref_name].first["id"] )
124
+ ware = AssayDepot::Ware.get( id: wares[AssayDepot::Ware.ref_name].first["id"] )
134
125
  wares[AssayDepot::Ware.ref_name].first["id"].should == ware["ware"]["id"]
135
126
  end
136
127
 
137
128
  it "get providers for a ware id" do
138
- response = AssayDepot::WareProvider.get( wares[AssayDepot::Ware.ref_name].first["id"] )
129
+ response = AssayDepot::WareProvider.get( id: wares[AssayDepot::Ware.ref_name].first["id"] )
139
130
  response[AssayDepot::WareProvider.ref_name].is_a?(Array).should == true
140
131
  end
141
132
  end
@@ -149,15 +140,15 @@ describe AssayDepot do
149
140
  @provider_id = providers[AssayDepot::Provider.ref_name].first["id"]
150
141
  @provider_name = providers[AssayDepot::Provider.ref_name].first["name"]
151
142
  sleep(1)
152
- @delete = AssayDepot::WareProvider.delete( @ware_id, @provider_id )
153
- @ware_provider_response = AssayDepot::WareProvider.post( @ware_id, @provider_id )
143
+ @delete = AssayDepot::WareProvider.delete( id: [@ware_id, @provider_id] )
144
+ @ware_provider_response = AssayDepot::WareProvider.post( id: [@ware_id, @provider_id] )
154
145
  # TODO: this should not be needed
155
146
  sleep(2)
156
- @ware_provider = AssayDepot::WareProvider.get( @ware_id )
157
- @provider_ware = AssayDepot::ProviderWare.get( @provider_id )
158
- @clean_up = AssayDepot::WareProvider.delete( @ware_id, @provider_id )
159
- @provider_clean_up = AssayDepot::WareProvider.get( @ware_id )
160
- @ware_clean_up = AssayDepot::ProviderWare.get( @provider_id )
147
+ @ware_provider = AssayDepot::WareProvider.get( id: @ware_id )
148
+ @provider_ware = AssayDepot::ProviderWare.get( id: @provider_id )
149
+ @clean_up = AssayDepot::WareProvider.delete( id: [@ware_id, @provider_id] )
150
+ @provider_clean_up = AssayDepot::WareProvider.get( id: @ware_id )
151
+ @ware_clean_up = AssayDepot::ProviderWare.get( id: @provider_id )
161
152
  end
162
153
 
163
154
  it "make sure provider is not published" do
@@ -197,9 +188,17 @@ describe AssayDepot do
197
188
  end
198
189
  end
199
190
 
191
+ context "quoted wares" do
192
+ let(:qw) { AssayDepot::QuotedWare.get() }
193
+
194
+ it "deny quoted wares" do
195
+ qw.is_a?(Array).should == false
196
+ end
197
+ end
198
+
200
199
  context "webhooks" do
201
200
  it "create a web hook for this user" do
202
- response = AssayDepot::Webhook.put({
201
+ response = AssayDepot::Webhook.put(body: {
203
202
  name: "This is another new 'name'.",
204
203
  bogus_key: "ignore_me"
205
204
  })
@@ -209,7 +208,7 @@ describe AssayDepot do
209
208
  end
210
209
 
211
210
  it "create a web hook for this user (patch) and verify (get)" do
212
- response = AssayDepot::Webhook.patch({
211
+ response = AssayDepot::Webhook.patch(body: {
213
212
  name: "And another new 'name'.",
214
213
  bogus_key: "ignore_me"
215
214
  })
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assaydepot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Petersen
8
+ - Ron Ranauro
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2020-07-29 00:00:00.000000000 Z
12
+ date: 2021-03-12 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: json
@@ -25,7 +26,7 @@ dependencies:
25
26
  - !ruby/object:Gem::Version
26
27
  version: '0'
27
28
  - !ruby/object:Gem::Dependency
28
- name: uri-query_params
29
+ name: rack
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
32
  - - ">="
@@ -80,15 +81,17 @@ dependencies:
80
81
  - - ">="
81
82
  - !ruby/object:Gem::Version
82
83
  version: '0'
83
- description: This is the first version of Assay Depot's Ruby SDK. It provides read
84
- access to Services and Vendors through assaydepot.com's JSON API.
84
+ description: The Scientist Ruby SDK. It provides read access to Services and Suppliers
85
+ through scientist.com's JSON API.
85
86
  email:
86
- - christopher.petersen@gmail.com
87
+ - chris@scientist.com
88
+ - ron@scientist.com
87
89
  executables: []
88
90
  extensions: []
89
91
  extra_rdoc_files: []
90
92
  files:
91
93
  - ".gitignore"
94
+ - ".rspec"
92
95
  - ".travis.yml"
93
96
  - Gemfile
94
97
  - LICENSE.md
@@ -103,6 +106,7 @@ files:
103
106
  - lib/assaydepot/event.rb
104
107
  - lib/assaydepot/model.rb
105
108
  - lib/assaydepot/version.rb
109
+ - spec/assaydepot_backoffice_spec.rb
106
110
  - spec/assaydepot_spec.rb
107
111
  - spec/assaydepot_wrapper_spec.rb
108
112
  homepage: https://github.com/assaydepot/assaydepot-rb
@@ -123,11 +127,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
127
  - !ruby/object:Gem::Version
124
128
  version: '0'
125
129
  requirements: []
126
- rubyforge_project:
127
- rubygems_version: 2.5.1
130
+ rubygems_version: 3.0.3
128
131
  signing_key:
129
132
  specification_version: 4
130
133
  summary: Provides read access to Assay Depot's Services and Vendors.
131
134
  test_files:
135
+ - spec/assaydepot_backoffice_spec.rb
132
136
  - spec/assaydepot_spec.rb
133
137
  - spec/assaydepot_wrapper_spec.rb