material_service_client 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5d59a2ec5fbdca6065dc237f7c83fc80823fc595
4
- data.tar.gz: 4df429c8fb65297bd8934c9314b230739c262584
3
+ metadata.gz: 913d0e9c2b98a4a2142d5f8087cffdb5d97c920d
4
+ data.tar.gz: b40a24db29bfd035b3f0ccaf46c3eec905c64d0a
5
5
  SHA512:
6
- metadata.gz: 10e785523716be1cad6acbc38a6be5ad391b2fd4036b68d5dc7c25c7417e8f2c59bdda4560465ef1f487ff303d28c628cacff930150ce7cac0855511daf30a93
7
- data.tar.gz: 7cde045256097b3951f2097679d9a07bb7156728fbd768c743a1498e4c04ee28685615ef943bc205f52802420e912e1dbed0706afa0c7aa3f711c87f0c0da1a5
6
+ metadata.gz: b61e26c437c0a5d1ce429c712dd66b8dbf195b15c5c1a28d2c929d9ce66b6b4a35c92fb5120a97e88fef56ad22f7ef744e3484ea0fdb603227d3a74ce79b965d
7
+ data.tar.gz: e34fb3413c50086eb5b78d4dbf3ee8025bde8bd5aa33bca3a9c6d2feac17e8e9f0205082d416cf9d38679493bfcc17843173ff4424df8719915b4b6f8986d2d9
@@ -1,51 +1,82 @@
1
1
  require "material_service_client/version"
2
+ require 'faraday'
3
+ require 'json'
2
4
 
3
5
  module MaterialServiceClient
4
- def self.post(data)
5
- conn = get_connection
6
- JSON.parse(conn.post('/materials', data.to_json).body)
7
- end
6
+ module Material
7
+ def self.post(data)
8
+ conn = MaterialServiceClient::get_connection
9
+ JSON.parse(conn.post('/materials', data.to_json).body)
10
+ end
8
11
 
9
- def self.put(data)
10
- uuid = data[:uuid]
11
- data_to_send = data.reject{|k,v| k.to_sym == :uuid}
12
+ def self.put(data)
13
+ uuid = data[:uuid]
14
+ data_to_send = data.reject{|k,v| k.to_sym == :uuid}
12
15
 
13
- conn = get_connection
14
- JSON.parse(conn.put('/materials/'+uuid, data_to_send.to_json).body)
15
- end
16
+ conn = MaterialServiceClient::get_connection
17
+ JSON.parse(conn.put('/materials/'+uuid, data_to_send.to_json).body)
18
+ end
19
+
20
+ def self.get(uuid)
21
+ return nil if uuid.nil?
22
+ conn = MaterialServiceClient::get_connection
23
+ JSON.parse(conn.get('/materials/'+uuid).body)
24
+ end
25
+
26
+ def self.valid?(uuids)
27
+ conn = MaterialServiceClient::get_connection
28
+ data = { materials: uuids }
16
29
 
17
- def self.get(uuid)
18
- return nil if uuid.nil?
19
- conn = get_connection
20
- JSON.parse(conn.get('/materials/'+uuid).body)
30
+ response = conn.post('/materials/validate', data.to_json)
31
+ response.body == 'ok'
32
+ end
33
+
34
+ def self.delete(uuid)
35
+ return nil if uuid.nil?
36
+ conn = MaterialServiceClient::get_connection
37
+ JSON.parse(conn.delete('/materials/'+uuid).body)
38
+ end
21
39
  end
22
40
 
23
- def self.valid?(uuids)
24
- conn = get_connection
25
- data = { materials: uuids }
26
-
27
- response = conn.post('/materials/validate', data.to_json)
28
-
29
- # response = conn.post do |req|
30
- # req.url '/materials/validate'
31
- # req.headers['Content-Type'] = 'application/json'
32
- # req.headers['Accept'] = 'application/json'
33
- # req.body = { materials: uuids }.to_json
34
- # end
35
- response.body == 'ok'
36
- end
41
+ module Container
42
+ def self.post(data)
43
+ conn = MaterialServiceClient::get_connection
44
+ JSON.parse(conn.post('/containers', data.to_json).body)
45
+ end
46
+
47
+ def self.put(data)
48
+ uuid = data[:uuid]
49
+ data_to_send = data.reject{|k,v| k.to_sym == :uuid}
50
+
51
+ conn = MaterialServiceClient::get_connection
52
+ JSON.parse(conn.put('/containers/'+uuid, data_to_send.to_json).body)
53
+ end
54
+
55
+ def self.get(uuid)
56
+ return nil if uuid.nil?
57
+ conn = MaterialServiceClient::get_connection
58
+ JSON.parse(conn.get('/containers/'+uuid).body)
59
+ end
60
+
61
+ def self.delete(uuid)
62
+ return nil if uuid.nil?
63
+ conn = MaterialServiceClient::get_connection
64
+ conn.delete('/containers/'+uuid)
65
+ end
66
+ end
37
67
 
38
68
  private
39
69
 
40
70
  def self.get_connection
41
- conn = Faraday.new(:url => Rails.application.config.material_url) do |faraday|
71
+ conn = Faraday.new(:url => ENV['MATERIALS_URL']) do |faraday|
42
72
  # faraday.use ZipkinTracer::FaradayHandler, 'eve'
43
- faraday.proxy Rails.application.config.material_url
73
+ faraday.proxy ENV['MATERIALS_URL']
44
74
  faraday.request :url_encoded
45
75
  faraday.response :logger
46
- faraday.adapter Faraday.default_adapter
76
+ faraday.adapter Faraday.default_adapter
47
77
  end
48
- conn.headers = {'Content-Type' => 'application/json'}
78
+ conn.headers = {'Content-Type' => 'application/json'}
49
79
  conn
50
80
  end
81
+
51
82
  end
@@ -1,3 +1,3 @@
1
1
  module MaterialServiceClient
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
18
  # to allow pushing to a single host or delete this section to allow pushing to any host.
19
-
19
+
20
20
  # if spec.respond_to?(:metadata)
21
21
  # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
22
22
  # else
@@ -35,4 +35,6 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency "rake", "~> 10.0"
36
36
  spec.add_development_dependency "rspec", "~> 3.0"
37
37
 
38
+ spec.add_dependency "faraday"
39
+
38
40
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: material_service_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harriet Craven
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Gem to access the material service API.
56
70
  email:
57
71
  - hc6@sanger.ac.uk