cdd 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ test-script.rb
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ script:
2
+ - bundle exec rake spec
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
- # CDD - Collaborative Drug Discovery
1
+ # CDD - Collaborative Drug Discovery [![Build Status](https://travis-ci.org/cpetersen/cdd.png?branch=master)](https://travis-ci.org/cpetersen/cdd) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/cpetersen/cdd)
2
2
 
3
3
  Collaborative Drug Discovery is a web based tool for storing and sharing pharmaceutical research. This is a ruby wrapper for their API.
4
4
 
5
+ CDD's API can be found [here](https://support.collaborativedrug.com/categories/20081556-cdd-api-documentation).
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -48,6 +50,17 @@ Returns a list of project objects that look like:
48
50
  [{"name"=>"Your Project Name", "id"=>1234}]
49
51
  ```
50
52
 
53
+ ## DataSets
54
+ Given a vault object, you can retrieve it's available data sets:
55
+ ```ruby
56
+ data_sets = vaults.first.data_sets
57
+ ```
58
+
59
+ Returns a list of data_set objects that look like:
60
+ ```ruby
61
+ [{"name"=>"Data Set X, "id"=>1234567}]
62
+ ```
63
+
51
64
  ## Searches
52
65
  Given a vault object, you can retrieve it's searches list:
53
66
  ```ruby
@@ -0,0 +1,6 @@
1
+ module CDD
2
+ class DataSet < Base
3
+ attr_accessor :name
4
+ attr_accessor :vault
5
+ end
6
+ end
data/lib/cdd/vault.rb CHANGED
@@ -2,6 +2,16 @@ module CDD
2
2
  class Vault < Base
3
3
  attr_accessor :name
4
4
 
5
+ def data_sets
6
+ @data_sets ||= client.execute(data_sets_url).collect do |hash|
7
+ CDD::DataSet.new(self.client, {:vault => self}.merge(hash))
8
+ end
9
+ end
10
+
11
+ def data_sets_url
12
+ "/api/v1/vaults/#{self.id}/data_sets"
13
+ end
14
+
5
15
  def projects
6
16
  @project ||= client.execute(projects_url).collect do |hash|
7
17
  CDD::Project.new(self.client, {:vault => self}.merge(hash))
data/lib/cdd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CDD
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/cdd.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "cdd/base"
2
2
  require "cdd/client"
3
+ require "cdd/data_set"
3
4
  require "cdd/export"
4
5
  require "cdd/project"
5
6
  require "cdd/search"
data/spec/cdd_spec.rb CHANGED
@@ -1,109 +1,136 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CDD do
4
-
5
4
  context "A default client" do
6
- context "when requesting vaults" do
7
- let(:token) { ENV["CDD_TOKEN_ID"] || "1234567890" }
8
- let(:client) { CDD::Client.new(token) }
5
+ let(:token) { ENV["CDD_TOKEN_ID"] || "1234567890" }
6
+ let(:client) { CDD::Client.new(token) }
7
+
8
+ it "should have the correct vaults_url" do
9
+ client.vaults_url.should == "/api/v1/vaults"
10
+ end
9
11
 
10
- it "should have the correct vaults_url" do
11
- client.vaults_url.should == "/api/v1/vaults"
12
+ it "should call the default vaults url" do
13
+ RestClient.should_receive(:get).with("https://app.collaborativedrug.com/api/v1/vaults", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "1234", :name => "Test Vault"}].to_json))
14
+ client.vaults
15
+ end
16
+
17
+ context "when requesting vaults" do
18
+ before(:all) do
19
+ RestClient.stub(:get).with("https://app.collaborativedrug.com/api/v1/vaults", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "1234", :name => "Test Vault"}].to_json))
12
20
  end
21
+ let(:vaults) { client.vaults }
13
22
 
14
- it "should call the default vaults url" do
15
- RestClient.should_receive(:get).with("https://app.collaborativedrug.com/api/v1/vaults", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "1234", :name => "Test Vault"}].to_json))
16
- client.vaults
23
+ it "should return an array of vaults" do
24
+ vaults.class.should == Array
25
+ vaults.first.class.should == CDD::Vault
17
26
  end
18
27
 
19
- context "when requesting vaults" do
20
- before(:all) do
21
- RestClient.stub(:get).with("https://app.collaborativedrug.com/api/v1/vaults", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "1234", :name => "Test Vault"}].to_json))
28
+ context "the vault" do
29
+ let(:vault) { vaults.first }
30
+
31
+ it "should have the correct values" do
32
+ vault.id.should == "1234"
33
+ vault.name.should == "Test Vault"
22
34
  end
23
- let(:vaults) { client.vaults }
24
35
 
25
- it "should return an array of vaults" do
26
- vaults.class.should == Array
27
- vaults.first.class.should == CDD::Vault
36
+ it "should have the correct default export_url" do
37
+ vault.export_url.should == "/api/v1/vaults/#{vault.id}/exports.csv"
28
38
  end
29
39
 
30
- context "the vault" do
31
- let(:vault) { vaults.first }
40
+ it "should have the correct csv export_url" do
41
+ vault.export_url("csv").should == "/api/v1/vaults/#{vault.id}/exports.csv"
42
+ end
32
43
 
33
- it "should have the correct values" do
34
- vault.id.should == "1234"
35
- vault.name.should == "Test Vault"
36
- end
44
+ it "should have the correct sdf export_url" do
45
+ vault.export_url("sdf").should == "/api/v1/vaults/#{vault.id}/exports.sdf"
46
+ end
37
47
 
38
- it "should have the correct default export_url" do
39
- vault.export_url.should == "/api/v1/vaults/#{vault.id}/exports.csv"
40
- end
48
+ it "should have the correct searches_url" do
49
+ vault.searches_url.should == "/api/v1/vaults/#{vault.id}/searches"
50
+ end
41
51
 
42
- it "should have the correct csv export_url" do
43
- vault.export_url("csv").should == "/api/v1/vaults/#{vault.id}/exports.csv"
44
- end
52
+ it "should call the default searches url" do
53
+ RestClient.should_receive(:get).with("https://app.collaborativedrug.com/api/v1/vaults/#{vault.id}/searches", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "12345", :name => "Test Search"}].to_json))
54
+ vault.searches
55
+ end
45
56
 
46
- it "should have the correct sdf export_url" do
47
- vault.export_url("sdf").should == "/api/v1/vaults/#{vault.id}/exports.sdf"
57
+ context "when requesting searches" do
58
+ before(:all) do
59
+ RestClient.stub(:get).with("https://app.collaborativedrug.com/api/v1/vaults/#{vault.id}/searches", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "12345", :name => "Test Search"}].to_json))
48
60
  end
61
+ let(:searches) { vault.searches }
49
62
 
50
- it "should have the correct searches_url" do
51
- vault.searches_url.should == "/api/v1/vaults/#{vault.id}/searches"
63
+ it "should return an array of searches" do
64
+ searches.class.should == Array
65
+ searches.first.class.should == CDD::Search
52
66
  end
53
67
 
54
- it "should call the default searches url" do
55
- RestClient.should_receive(:get).with("https://app.collaborativedrug.com/api/v1/vaults/#{vault.id}/searches", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "12345", :name => "Test Search"}].to_json))
56
- vault.searches
57
- end
68
+ context "the search" do
69
+ let(:search) { searches.first }
58
70
 
59
- context "when requesting searches" do
60
- before(:all) do
61
- RestClient.stub(:get).with("https://app.collaborativedrug.com/api/v1/vaults/#{vault.id}/searches", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "12345", :name => "Test Search"}].to_json))
71
+ it "should have the correct values" do
72
+ search.id.should == "12345"
73
+ search.name.should == "Test Search"
62
74
  end
63
- let(:searches) { vault.searches }
75
+ end
76
+ end
64
77
 
65
- it "should return an array of searches" do
66
- searches.class.should == Array
67
- searches.first.class.should == CDD::Search
68
- end
78
+ it "should have the correct data_sets_url" do
79
+ vaults.first.data_sets_url.should == "/api/v1/vaults/#{vaults.first.id}/data_sets"
80
+ end
69
81
 
70
- context "the search" do
71
- let(:search) { searches.first }
82
+ it "should call the default data_sets url" do
83
+ RestClient.should_receive(:get).with("https://app.collaborativedrug.com/api/v1/vaults/#{vaults.first.id}/data_sets", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "12345678", :name => "Test Data Set"}].to_json))
84
+ vault.data_sets
85
+ end
72
86
 
73
- it "should have the correct values" do
74
- search.id.should == "12345"
75
- search.name.should == "Test Search"
76
- end
77
- end
87
+ context "when requesting data_sets" do
88
+ before(:all) do
89
+ RestClient.stub(:get).with("https://app.collaborativedrug.com/api/v1/vaults/#{vaults.first.id}/data_sets", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "12345678", :name => "Test Data Set"}].to_json))
78
90
  end
91
+ let(:data_sets) { vault.data_sets }
79
92
 
80
- it "should have the correct projects_url" do
81
- vaults.first.projects_url.should == "/api/v1/vaults/#{vaults.first.id}/projects"
93
+ it "should return an array of data_sets" do
94
+ data_sets.class.should == Array
95
+ data_sets.first.class.should == CDD::DataSet
82
96
  end
83
97
 
84
- it "should call the default projects url" do
85
- RestClient.should_receive(:get).with("https://app.collaborativedrug.com/api/v1/vaults/#{vaults.first.id}/projects", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "123456", :name => "Test Project"}].to_json))
86
- vault.projects
87
- end
98
+ context "the data_set" do
99
+ let(:data_set) { data_sets.first }
88
100
 
89
- context "when requesting projects" do
90
- before(:all) do
91
- RestClient.stub(:get).with("https://app.collaborativedrug.com/api/v1/vaults/#{vaults.first.id}/projects", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "123456", :name => "Test Project"}].to_json))
101
+ it "should have the correct values" do
102
+ data_set.id.should == "12345678"
103
+ data_set.name.should == "Test Data Set"
92
104
  end
93
- let(:projects) { vault.projects }
105
+ end
106
+ end
94
107
 
95
- it "should return an array of projects" do
96
- projects.class.should == Array
97
- projects.first.class.should == CDD::Project
98
- end
108
+ it "should have the correct projects_url" do
109
+ vaults.first.projects_url.should == "/api/v1/vaults/#{vaults.first.id}/projects"
110
+ end
111
+
112
+ it "should call the default projects url" do
113
+ RestClient.should_receive(:get).with("https://app.collaborativedrug.com/api/v1/vaults/#{vaults.first.id}/projects", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "123456", :name => "Test Project"}].to_json))
114
+ vault.projects
115
+ end
116
+
117
+ context "when requesting projects" do
118
+ before(:all) do
119
+ RestClient.stub(:get).with("https://app.collaborativedrug.com/api/v1/vaults/#{vaults.first.id}/projects", { :params=>{} , "X-CDD-Token" => token}).and_return(fake_response([{:id => "123456", :name => "Test Project"}].to_json))
120
+ end
121
+ let(:projects) { vault.projects }
122
+
123
+ it "should return an array of projects" do
124
+ projects.class.should == Array
125
+ projects.first.class.should == CDD::Project
126
+ end
99
127
 
100
- context "the project" do
101
- let(:project) { projects.first }
128
+ context "the project" do
129
+ let(:project) { projects.first }
102
130
 
103
- it "should have the correct values" do
104
- project.id.should == "123456"
105
- project.name.should == "Test Project"
106
- end
131
+ it "should have the correct values" do
132
+ project.id.should == "123456"
133
+ project.name.should == "Test Project"
107
134
  end
108
135
  end
109
136
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cdd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-19 00:00:00.000000000 Z
12
+ date: 2013-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -83,6 +83,7 @@ extensions: []
83
83
  extra_rdoc_files: []
84
84
  files:
85
85
  - .gitignore
86
+ - .travis.yml
86
87
  - Gemfile
87
88
  - LICENSE
88
89
  - README.md
@@ -91,6 +92,7 @@ files:
91
92
  - lib/cdd.rb
92
93
  - lib/cdd/base.rb
93
94
  - lib/cdd/client.rb
95
+ - lib/cdd/data_set.rb
94
96
  - lib/cdd/export.rb
95
97
  - lib/cdd/project.rb
96
98
  - lib/cdd/search.rb
@@ -112,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
114
  version: '0'
113
115
  segments:
114
116
  - 0
115
- hash: 3887554079488693763
117
+ hash: 3574982497320562979
116
118
  required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  none: false
118
120
  requirements:
@@ -121,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  version: '0'
122
124
  segments:
123
125
  - 0
124
- hash: 3887554079488693763
126
+ hash: 3574982497320562979
125
127
  requirements: []
126
128
  rubyforge_project:
127
129
  rubygems_version: 1.8.24