secureshare-ruby 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -1
- data/Rakefile +6 -0
- data/lib/secureshare.rb +11 -9
- data/lib/secureshare/client.rb +43 -0
- data/lib/secureshare/{bucket.rb → vault.rb} +4 -4
- data/secureshare-ruby.gemspec +2 -1
- data/spec/secureshare/client_spec.rb +46 -0
- data/spec/secureshare_spec.rb +24 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/support/fake_response.rb +15 -0
- metadata +32 -5
- data/spec/secureshare/ruby_spec.rb +0 -9
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format
|
1
|
+
--format progress
|
2
2
|
--color
|
data/Rakefile
CHANGED
data/lib/secureshare.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
require 'rest_client'
|
2
|
-
require 'secureshare/
|
2
|
+
require 'secureshare/vault'
|
3
3
|
require 'secureshare/document'
|
4
4
|
require "net/http"
|
5
5
|
require 'secureshare/exception'
|
6
6
|
|
7
7
|
module SecureShare
|
8
|
-
@@config = {
|
8
|
+
@@config = {
|
9
|
+
endpoint: 'https://api.secureshare.com.au'
|
10
|
+
}
|
9
11
|
|
10
12
|
def self.config options={}
|
11
13
|
@@config.merge! options
|
12
14
|
end
|
13
15
|
|
14
|
-
def self.
|
15
|
-
resource = RestClient::Resource.new "#{@@config[:endpoint]}/
|
16
|
-
response = resource.get :authorization => %{Token token="#{@@config[:
|
17
|
-
|
16
|
+
def self.fetch_vault vault_id
|
17
|
+
resource = RestClient::Resource.new "#{@@config[:endpoint]}/v1/#{@@config[:api_key]}/vaults/#{vault_id}"
|
18
|
+
response = resource.get :authorization => %{Token token="#{@@config[:api_secret]}"}, :content_type => :json, :accept => :json
|
19
|
+
vault = Vault.new(JSON.parse(response.body))
|
18
20
|
end
|
19
21
|
|
20
|
-
def self.
|
21
|
-
resource = RestClient::Resource.new "#{@@config[:endpoint]}/
|
22
|
+
def self.follow_vault vault_id, email, follow_url
|
23
|
+
resource = RestClient::Resource.new "#{@@config[:endpoint]}/v1/#{@@config[:api_key]}/vaults/#{vault_id}/follow"
|
22
24
|
begin
|
23
|
-
resource.post({ :email => email, :site_name =>
|
25
|
+
resource.post({ :email => email, :site_name => follow_url }, {:authorization => %{Token token="#{@@config[:api_secret]}"}, :content_type => :json, :accept => :json})
|
24
26
|
rescue RestClient::UnprocessableEntity => e
|
25
27
|
error_json = JSON.parse e.http_body
|
26
28
|
raise SecureShare::RestException.new(*error_json.first)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module SecureShare
|
4
|
+
class Client
|
5
|
+
|
6
|
+
def initialize endpoint, access_token, site_name
|
7
|
+
@endpoint = endpoint
|
8
|
+
@access_token = access_token
|
9
|
+
@site_name = site_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.for endpoint, access_token, site_name
|
13
|
+
new(endpoint)
|
14
|
+
end
|
15
|
+
|
16
|
+
def fetch_vault vault_id
|
17
|
+
response = rest_client.get "#{@endpoint}/api/v1/vaults/#{vault_id}", headers
|
18
|
+
JSON.parse(response.body)
|
19
|
+
end
|
20
|
+
|
21
|
+
def follow_vault vault_id, email
|
22
|
+
response = rest_client.post("#{@endpoint}/api/v1/vaults/#{vault_id}/follow", { :email => email, :site_name => @site_name}, headers)
|
23
|
+
JSON.parse(response.body)
|
24
|
+
rescue RestClient::UnprocessableEntity => e
|
25
|
+
error_json = JSON.parse e.http_body
|
26
|
+
raise SecureShare::RestException.new(*error_json.first)
|
27
|
+
end
|
28
|
+
|
29
|
+
def rest_client= rest_client
|
30
|
+
@rest_client = rest_client
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def rest_client
|
36
|
+
@rest_client || RestClient
|
37
|
+
end
|
38
|
+
|
39
|
+
def headers
|
40
|
+
{:authorization => %{Token token="#{@access_token}"}, :content_type => :json, :accept => :json}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module SecureShare
|
2
|
-
class
|
3
|
-
def initialize
|
4
|
-
@name =
|
5
|
-
@documents =
|
2
|
+
class Vault
|
3
|
+
def initialize vault_json
|
4
|
+
@name = vault_json["name"]
|
5
|
+
@documents = vault_json["documents"].map do |document_json|
|
6
6
|
Document.new document_json
|
7
7
|
end
|
8
8
|
end
|
data/secureshare-ruby.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "secureshare-ruby"
|
7
|
-
gem.version = "0.0.
|
7
|
+
gem.version = "0.0.9"
|
8
8
|
gem.authors = ["Chris Aitchison"]
|
9
9
|
gem.email = ["chris.aitchison@sodalis.com.au"]
|
10
10
|
gem.description = %q{SecureShare Ruby API}
|
@@ -20,4 +20,5 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_runtime_dependency 'rest-client'
|
21
21
|
|
22
22
|
gem.add_development_dependency "rake"
|
23
|
+
gem.add_development_dependency "rspec"
|
23
24
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'secureshare/client'
|
3
|
+
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
describe "SecureShare::RestClient" do
|
7
|
+
|
8
|
+
let(:rest_client) { double }
|
9
|
+
|
10
|
+
before do
|
11
|
+
@client = SecureShare::Client.new 'http://example.com', '12345', 'http://app.com'
|
12
|
+
@client.rest_client = rest_client
|
13
|
+
end
|
14
|
+
|
15
|
+
def headers
|
16
|
+
{:authorization => %{Token token="12345"}, :content_type => :json, :accept => :json}
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "fetching a vault" do
|
20
|
+
it "invokes RestClient correctly" do
|
21
|
+
rest_client.should_receive(:get).with("http://example.com/api/v1/vaults/abc", headers).and_return(FakeResponse.new({"some" => "json"}))
|
22
|
+
@client.fetch_vault('abc').should == {'some' => 'json'}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "following a vault" do
|
27
|
+
describe 'when there are no validation errors' do
|
28
|
+
it 'returns empty json' do
|
29
|
+
rest_client.should_receive(:post).with("http://example.com/api/v1/vaults/abc/follow",{email: 'a@b.com', site_name: 'http://app.com'}, headers).and_return(OpenStruct.new(body: '{}', code: 200))
|
30
|
+
@client.follow_vault('abc', 'a@b.com').should == {}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'when the email is already registered' do
|
35
|
+
it 'raises a SecureShare::RestException' do
|
36
|
+
rest_client.should_receive(:post).with("http://example.com/api/v1/vaults/abc/follow",{email: 'a@b.com', site_name: 'http://app.com'}, headers).and_raise(RestClient::UnprocessableEntity.new(OpenStruct.new(body: '{"email": "is already registered"}', code: 422)))
|
37
|
+
begin
|
38
|
+
@client.follow_vault('abc', 'a@b.com')
|
39
|
+
rescue SecureShare::RestException => e
|
40
|
+
e.field.should == "email"
|
41
|
+
e.message.should == "is already registered"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
require 'secureshare'
|
5
|
+
|
6
|
+
describe "SecureShare Ruby API" do
|
7
|
+
describe "when configured correctly" do
|
8
|
+
before do
|
9
|
+
SecureShare.config({
|
10
|
+
endpoint: 'https://example.com',
|
11
|
+
access_token: '3.14159',
|
12
|
+
site_name: 'http://app.com'
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "can fetch a vault" do
|
17
|
+
pending
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can follow a vault" do
|
21
|
+
pending
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secureshare-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
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-
|
12
|
+
date: 2013-04-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
46
62
|
description: SecureShare Ruby API
|
47
63
|
email:
|
48
64
|
- chris.aitchison@sodalis.com.au
|
@@ -57,12 +73,15 @@ files:
|
|
57
73
|
- README.md
|
58
74
|
- Rakefile
|
59
75
|
- lib/secureshare.rb
|
60
|
-
- lib/secureshare/
|
76
|
+
- lib/secureshare/client.rb
|
61
77
|
- lib/secureshare/document.rb
|
62
78
|
- lib/secureshare/exception.rb
|
79
|
+
- lib/secureshare/vault.rb
|
63
80
|
- secureshare-ruby.gemspec
|
64
|
-
- spec/secureshare/
|
81
|
+
- spec/secureshare/client_spec.rb
|
82
|
+
- spec/secureshare_spec.rb
|
65
83
|
- spec/spec_helper.rb
|
84
|
+
- spec/support/fake_response.rb
|
66
85
|
homepage: ''
|
67
86
|
licenses:
|
68
87
|
- MIT
|
@@ -76,12 +95,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
95
|
- - ! '>='
|
77
96
|
- !ruby/object:Gem::Version
|
78
97
|
version: '0'
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
hash: 3912854031429418768
|
79
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
102
|
none: false
|
81
103
|
requirements:
|
82
104
|
- - ! '>='
|
83
105
|
- !ruby/object:Gem::Version
|
84
106
|
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: 3912854031429418768
|
85
110
|
requirements: []
|
86
111
|
rubyforge_project:
|
87
112
|
rubygems_version: 1.8.23
|
@@ -89,5 +114,7 @@ signing_key:
|
|
89
114
|
specification_version: 3
|
90
115
|
summary: SecureShare Ruby API
|
91
116
|
test_files:
|
92
|
-
- spec/secureshare/
|
117
|
+
- spec/secureshare/client_spec.rb
|
118
|
+
- spec/secureshare_spec.rb
|
93
119
|
- spec/spec_helper.rb
|
120
|
+
- spec/support/fake_response.rb
|