oneview 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -1
- data/lib/oneview/api/contacts.rb +9 -3
- data/lib/oneview/version.rb +1 -1
- data/spec/oneview/api/contacts_spec.rb +46 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04df1d92f090b2ec6650d15318893970addf3235
|
4
|
+
data.tar.gz: 2ef2e2f7e80737b305b3158c8b644cf4e2f747cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93b6b0be44b4476720145b0624d0efb30041e72f54d11b33dc90cd3238fd40378f20f6cb15906bc58becf36b8f5417616297631fb9b1658862b36955fa0d1d03
|
7
|
+
data.tar.gz: 75001d5c6463ce9993c7c0d116e5f3a51c255d7487593df6857c7ceaf3719357a0e6589d5f4e0ce77df3ee71f29c8ad1d5aabae0049cd71b54b57ae8ffda1287
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ Create a new instance of Oneview class passing your access token:
|
|
30
30
|
|
31
31
|
With the client instance, you can access the following resources:
|
32
32
|
|
33
|
-
* Contacts (client.contacts) **
|
33
|
+
* Contacts (client.contacts) **Create and Update**
|
34
34
|
* Sms Sending (client.sms)
|
35
35
|
* Email Sending (client.email)
|
36
36
|
|
@@ -48,6 +48,13 @@ Currently the following entities are implemented:
|
|
48
48
|
* [Email](lib/oneview/entity/email.rb)
|
49
49
|
* [SMS](lib/oneview/entity/sms.rb)
|
50
50
|
|
51
|
+
### Updating records
|
52
|
+
It can accept a hash with the parameters as described in the API [documentation] or an Entity object that reflects the API fields.
|
53
|
+
|
54
|
+
Currently the following entities are implemented:
|
55
|
+
|
56
|
+
* [Contact](lib/oneview/entity/contact.rb)
|
57
|
+
|
51
58
|
### Reading the response
|
52
59
|
All methods return an Oneview::Client::Response object. This objects contains the following attributes:
|
53
60
|
|
data/lib/oneview/api/contacts.rb
CHANGED
@@ -4,18 +4,24 @@ module Oneview
|
|
4
4
|
require_all 'oneview/entity', 'contact', 'dynamic_field', 'phone'
|
5
5
|
|
6
6
|
base_uri "http://www.oneview.com.br/api/contacts"
|
7
|
-
|
7
|
+
|
8
8
|
def create(data)
|
9
9
|
return parse_response(self.class.post("/", :body => build_body(data), :headers => header)) if data.is_a?(Hash)
|
10
10
|
return parse_response(self.class.post("/", :body => build_body(data.as_parameter), :headers => header)) if data.is_a?(Oneview::Entity::Contact)
|
11
11
|
raise ArgumentError
|
12
12
|
end
|
13
13
|
alias :new :create
|
14
|
-
|
14
|
+
|
15
|
+
def update(id, data)
|
16
|
+
return parse_response(self.class.patch("/" + id, :body => build_body(data), :headers => header)) if data.is_a?(Hash)
|
17
|
+
return parse_response(self.class.patch("/" + id, :body => build_body(data.as_parameter), :headers => header)) if data.is_a?(Oneview::Entity::Contact)
|
18
|
+
raise ArgumentError
|
19
|
+
end
|
20
|
+
|
15
21
|
private
|
16
22
|
def build_body(parameters)
|
17
23
|
super({:contact => parameters})
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
21
|
-
end
|
27
|
+
end
|
data/lib/oneview/version.rb
CHANGED
@@ -50,4 +50,50 @@ RSpec.describe Oneview::Api::Contacts do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
describe "updating" do
|
55
|
+
let(:contact_params) {{:contact => {:name => "name", :email => "email", :id => "23" }, :access_token => "abc"}}
|
56
|
+
let(:header) {{"Content-Type" => "application/json", "Accept" => "application/json"}}
|
57
|
+
|
58
|
+
before(:each) do
|
59
|
+
phone = Oneview::Entity::Phone.new
|
60
|
+
phone.country_code = "+55"
|
61
|
+
phone.area_code = "12"
|
62
|
+
phone.number = "998998789"
|
63
|
+
|
64
|
+
@contact = Oneview::Entity::Contact.new
|
65
|
+
@contact.id = "23"
|
66
|
+
@contact.name = "name"
|
67
|
+
@contact.email = "email@email.com"
|
68
|
+
@contact.birthday = "14/10/2014"
|
69
|
+
@contact.city = "city"
|
70
|
+
@contact.state = "state"
|
71
|
+
@contact.zip_code = "12233-444"
|
72
|
+
@contact.phone = phone
|
73
|
+
|
74
|
+
stub_request(:patch, "http://www.oneview.com.br/api/contacts/23").to_return(:status => 200)
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "with raw parameters" do
|
78
|
+
it "should patch to the contacts url" do
|
79
|
+
expect(Oneview::Api::Contacts).to receive(:patch).with("/" + contact_params[:contact][:id], :body => contact_params.to_json, :headers => header).and_call_original
|
80
|
+
|
81
|
+
Oneview.new("abc").contacts.update("23",{:name => "name", :email => "email", :id => "23"})
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "with entity parameter" do
|
86
|
+
it "should patch to the contacts url" do
|
87
|
+
expect(Oneview::Api::Contacts).to receive(:patch).with("/" + @contact.id, :body => {:contact => @contact.as_parameter, :access_token => "abc"}.to_json, :headers => header).and_call_original
|
88
|
+
|
89
|
+
Oneview.new("abc").contacts.update(@contact.id, @contact)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "with invalid parameter" do
|
94
|
+
it "should raise ArgumentError when passing neither a Hash nor a Contact" do
|
95
|
+
expect{Oneview.new("abc").contacts.create(Array.new)}.to raise_error(ArgumentError)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
53
99
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oneview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gustavo Berdugo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
96
|
version: '0'
|
97
97
|
requirements: []
|
98
98
|
rubyforge_project:
|
99
|
-
rubygems_version: 2.4.
|
99
|
+
rubygems_version: 2.4.8
|
100
100
|
signing_key:
|
101
101
|
specification_version: 4
|
102
102
|
summary: This gem provides integration with Oneview APIs (http://www.oneview.com.br/)
|