assaydepot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in assaydepot.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Christopher Petersen
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.
@@ -0,0 +1,64 @@
1
+ # AssayDepot
2
+
3
+ Ruby interface for Assay Depot's online laboratory (http://www.assaydepot.com).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'assaydepot'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install assaydepot
18
+
19
+ ## Basic Usage
20
+
21
+ ```ruby
22
+ require 'assaydepot'
23
+ AssayDepot.configure do |config|
24
+ config.auth_token = "1234567890"
25
+ config.url = "http://localhost:3000/api"
26
+ end
27
+ wares = AssayDepot::Ware.find("Antibody")
28
+ wares.total
29
+ ```
30
+
31
+ ## Using Facets
32
+
33
+ ```ruby
34
+ wares = AssayDepot::Ware.where(:ware_type => "CustomService")
35
+ wares.facets
36
+ ```
37
+
38
+ ## Chainable Commands
39
+
40
+ ```ruby
41
+ wares = AssayDepot::Ware.where(:ware_type => "CustomService").where(:available_provider_names => "Assay Depot").page(2)
42
+ wares.first["name"]
43
+ ```
44
+
45
+ ## Providers
46
+
47
+ ```ruby
48
+ providers = AssayDepot::Provider.where(:starts_with => "a").per_page(600)
49
+ providers.count
50
+ ```
51
+
52
+ ## Get Details
53
+ ```ruby
54
+ providers = AssayDepot::Provider.where(:starts_with => "a")
55
+ AssayDepot::Provider.get(providers.first["id"])
56
+ ```
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/assaydepot/version', __FILE__)
3
+
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.}
8
+ gem.summary = %q{Provides read access to Assay Depot's Services and Vendors.}
9
+ gem.homepage = "https://github.com/assaydepot/assaydepot-rb"
10
+
11
+ gem.add_dependency('json')
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "assaydepot"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = AssayDepot::VERSION
19
+ end
@@ -0,0 +1,26 @@
1
+ require "assaydepot/version"
2
+ require "assaydepot/configurable"
3
+ require "assaydepot/client"
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
14
+
15
+ module AssayDepot
16
+ class << self
17
+ include AssayDepot::Configurable
18
+ end
19
+
20
+ # Delegate to a AssayDepot::Client
21
+ #
22
+ # @return [AssayDepot::Client]
23
+ def client
24
+ AssayDepot::Client.new(options)
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ require "open-uri"
2
+ require "json"
3
+
4
+ module AssayDepot
5
+ class Client
6
+ def initialize(options={})
7
+ @search_type = options[:search_type] || "wares"
8
+ end
9
+
10
+ def search_url(query, facets, params={})
11
+ "#{AssayDepot.url}/#{@search_type}.json?#{params.collect { |k,v| "#{k}=#{v.to_s.gsub(" ","+")}"}.join("&")}"
12
+ end
13
+
14
+ def get_url(id, params={})
15
+ "#{AssayDepot.url}/#{@search_type}/#{id}.json?#{params.collect { |k,v| "#{k}=#{v.to_s.gsub(" ","+")}"}.join("&")}"
16
+ end
17
+
18
+ def search(query, facets, params={})
19
+ params["auth_token"] = AssayDepot.auth_token
20
+ params["q"] = query
21
+ facets.map do |name,value|
22
+ params["facets[#{name}][]"] = value
23
+ end
24
+ JSON.parse(open(search_url(query, facets, params)).read)
25
+ end
26
+
27
+ def get(id, params={})
28
+ params["auth_token"] = AssayDepot.auth_token
29
+ JSON.parse(open(get_url(id, params)).read)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ module AssayDepot
2
+ module Configurable
3
+
4
+ # Convenience method to allow configuration options to be set in a block
5
+ def configure
6
+ yield self
7
+ self
8
+ end
9
+
10
+ CONFIG_KEYS = [
11
+ :url,
12
+ :auth_token,
13
+ ] unless defined? CONFIG_KEYS
14
+ attr_accessor *CONFIG_KEYS
15
+
16
+ class << self
17
+ def keys
18
+ @keys ||= CONFIG_KEYS
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,109 @@
1
+ module AssayDepot
2
+ module Model
3
+ module ClassMethods
4
+ def find(query)
5
+ self.new.find(query)
6
+ end
7
+ def where(conditions={})
8
+ self.new.where(conditions)
9
+ end
10
+ def get(id)
11
+ Client.new(:search_type => search_type).get(id)
12
+ end
13
+ end
14
+
15
+ def self.included(base)
16
+ base.extend ClassMethods
17
+ base.extend Forwardable
18
+ base.def_delegators :private_results,
19
+ :each,
20
+ :[],
21
+ :count,
22
+ :collect,
23
+ :map,
24
+ :tap,
25
+ :<=>,
26
+ :compact,
27
+ :each_index,
28
+ :each_with_index,
29
+ :empty?,
30
+ :flatten,
31
+ :include?,
32
+ :index,
33
+ :length,
34
+ :first,
35
+ :last,
36
+ :keep_if,
37
+ :reject,
38
+ :reverse
39
+
40
+ attr_accessor :search_query
41
+ attr_accessor :search_facets
42
+ attr_accessor :search_options
43
+
44
+ def initialize(options={})
45
+ @search_query = options[:search_query] || ""
46
+ @search_facets = options[:search_facets] || {}
47
+ @search_options = options[:search_options] || {:page => 1}
48
+ end
49
+
50
+ def initialize_copy(source)
51
+ super
52
+ @search_query = @search_query.dup
53
+ @search_facets = @search_facets.dup
54
+ end
55
+
56
+ def query_time
57
+ search_results["query_time"]
58
+ end
59
+ def total
60
+ search_results["total"]
61
+ end
62
+ def page
63
+ search_results["page"]
64
+ end
65
+ def per_page
66
+ search_results["per_page"]
67
+ end
68
+ def facets
69
+ search_results["facets"]
70
+ end
71
+
72
+ def page(page_num)
73
+ options( { "page" => page_num } )
74
+ end
75
+
76
+ def per_page(page_size)
77
+ options( { "per_page" => page_size } )
78
+ end
79
+
80
+ def find(query)
81
+ result = self.clone
82
+ result.search_query = search_query
83
+ result
84
+ end
85
+
86
+ def where(conditions={})
87
+ result = self.clone
88
+ result.search_facets = self.search_facets ? self.search_facets.merge(conditions) : conditions
89
+ result
90
+ end
91
+
92
+ def options(options={})
93
+ result = self.clone
94
+ result.search_options = self.search_options ? self.search_options.merge(options) : options
95
+ result
96
+ end
97
+
98
+ def private_results
99
+ search_results[self.class.ref_name]
100
+ end
101
+ def search_results
102
+ unless @search_results
103
+ @search_results = Client.new(:search_type => self.class.search_type).search(search_query, search_facets, search_options)
104
+ end
105
+ @search_results
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,12 @@
1
+ module AssayDepot
2
+ class Provider
3
+ include Model
4
+
5
+ def self.search_type
6
+ "providers"
7
+ end
8
+ def self.ref_name
9
+ "provider_refs"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module AssayDepot
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,12 @@
1
+ module AssayDepot
2
+ class Ware
3
+ include Model
4
+
5
+ def self.search_type
6
+ "wares"
7
+ end
8
+ def self.ref_name
9
+ "ware_refs"
10
+ end
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: assaydepot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Petersen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: This is the first version of Assay Depot's Ruby SDK. It provides read
31
+ access to Services and Vendors through assaydepot.com's JSON API.
32
+ email:
33
+ - christopher.petersen@gmail.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE
41
+ - README.md
42
+ - Rakefile
43
+ - assaydepot.gemspec
44
+ - lib/assaydepot.rb
45
+ - lib/assaydepot/client.rb
46
+ - lib/assaydepot/configurable.rb
47
+ - lib/assaydepot/model.rb
48
+ - lib/assaydepot/provider.rb
49
+ - lib/assaydepot/version.rb
50
+ - lib/assaydepot/ware.rb
51
+ homepage: https://github.com/assaydepot/assaydepot-rb
52
+ licenses: []
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.24
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Provides read access to Assay Depot's Services and Vendors.
75
+ test_files: []