gram_v2_client 2.1.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/bin/console +5 -0
- data/gram_v2_client.gemspec +1 -0
- data/lib/gram_v2_client.rb +2 -5
- data/lib/gram_v2_client/base.rb +16 -2
- data/lib/gram_v2_client/exceptions.rb +26 -0
- data/lib/gram_v2_client/rspec/gram_account_mocker.rb +87 -0
- data/lib/gram_v2_client/version.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 847f2ca7213f515db7970c95459314a0d0c91c3e
|
4
|
+
data.tar.gz: 9036514bbbf355b38ed653495c7c3a9312cf3ed1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35c877bab1fe2fb13136b84ae6b96d71703474172b50c2c4a3d0f1b68b150d23fb649bba1c674ef776f712a4a7c950987a7f24aff1d32bfdc8ad3270d23062b2
|
7
|
+
data.tar.gz: 6298cfd9ba8d8a585a0f4df818bc7a3788d322593c6952e49f47b73099a0f3d9ebf3d8ae6e29330e5e16ff539d3fadb2f36404b024975f1da5267b0e96d09955
|
data/.gitignore
CHANGED
data/bin/console
CHANGED
@@ -10,5 +10,10 @@ require "gram_v2_client"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
+
#You can add a file bin/env.rb to set convenience environment such as configuration
|
14
|
+
env_path=File.expand_path("./env.rb",File.dirname(__FILE__))
|
15
|
+
require env_path if File.file?(env_path)
|
16
|
+
|
17
|
+
|
13
18
|
require "irb"
|
14
19
|
IRB.start
|
data/gram_v2_client.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
spec.add_dependency 'activeresource', "~> 4.0"
|
30
30
|
|
31
|
+
spec.add_development_dependency "byebug", "~> 9.0"
|
31
32
|
spec.add_development_dependency "bundler", "~> 1.11"
|
32
33
|
spec.add_development_dependency "rake", "~> 10.0"
|
33
34
|
spec.add_development_dependency "rspec", "~> 3.0"
|
data/lib/gram_v2_client.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_resource'
|
2
|
+
require 'gram_v2_client/exceptions'
|
2
3
|
require 'gram_v2_client/configuration'
|
3
4
|
require 'gram_v2_client/base'
|
4
5
|
require 'gram_v2_client/account'
|
@@ -8,11 +9,7 @@ require 'gram_v2_client/version'
|
|
8
9
|
|
9
10
|
class GramV2Client
|
10
11
|
def self.init_test
|
11
|
-
|
12
|
-
c.site = "http://localhost:3000/api/v2"
|
13
|
-
c.user = "admin"
|
14
|
-
c.password = "password"
|
15
|
-
end
|
12
|
+
|
16
13
|
end
|
17
14
|
|
18
15
|
end
|
data/lib/gram_v2_client/base.rb
CHANGED
@@ -1,13 +1,27 @@
|
|
1
1
|
require 'active_resource'
|
2
2
|
|
3
3
|
class GramV2Client::Base < ActiveResource::Base
|
4
|
-
|
5
|
-
|
4
|
+
|
6
5
|
def to_param
|
7
6
|
uuid
|
8
7
|
end
|
9
8
|
|
10
9
|
class << self
|
10
|
+
|
11
|
+
def find(*args,&block)
|
12
|
+
begin
|
13
|
+
super(*args,&block)
|
14
|
+
rescue ActiveResource::ResourceNotFound => e
|
15
|
+
raise GramV2Client::ResourceNotFound.new(
|
16
|
+
resource: self.name,
|
17
|
+
query: args.first,
|
18
|
+
source_exception: e
|
19
|
+
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# This is set to enable Configuration change at runtime.
|
11
25
|
def site
|
12
26
|
if GramV2Client.configuration.site
|
13
27
|
if super.to_s != URI.parse(GramV2Client.configuration.site).to_s
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class GramV2Client
|
2
|
+
|
3
|
+
class ResourceNotFound < StandardError
|
4
|
+
|
5
|
+
attr_reader :query
|
6
|
+
attr_reader :resource
|
7
|
+
attr_reader :source_exception
|
8
|
+
|
9
|
+
|
10
|
+
def initialize(query: nil, resource: nil, source_exception: nil)
|
11
|
+
@error=self.class.name
|
12
|
+
@query=query
|
13
|
+
@resource=resource
|
14
|
+
@source_exception=source_exception
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
message = "Failed."
|
19
|
+
message << " #{resource} not found" if resource
|
20
|
+
message << " with query '#{query}'" if query
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "base64"
|
2
|
+
class GramAccountMocker
|
3
|
+
|
4
|
+
|
5
|
+
DEFAULT_GRAM_ACCOUNT={
|
6
|
+
"uuid"=>"12345678-1234-1234-1234-123456789012",
|
7
|
+
"hruid"=>"francois.dupont.2011",
|
8
|
+
"firstname"=>"Francois",
|
9
|
+
"lastname"=>"Dupont",
|
10
|
+
"id_soce"=>"84189",
|
11
|
+
"enable"=>"TRUE",
|
12
|
+
"id"=>98765,
|
13
|
+
"uid_number"=>99765,
|
14
|
+
"gid_number"=>99765,
|
15
|
+
"home_directory"=>"/nonexistant",
|
16
|
+
"alias"=>["francois.dupont.2011", "98765", "98765J"],
|
17
|
+
"password"=>"Not Display",
|
18
|
+
"email"=>"francois.dupont",
|
19
|
+
"email_forge"=>"francois.dupont@poubs.org",
|
20
|
+
"birthdate"=>"1987-09-17 00:00:00",
|
21
|
+
"login_validation_check"=>"CGU=2015-06-04;",
|
22
|
+
"description"=>"Agoram inscription - via module register - creation 2015-06-04 11:32:48",
|
23
|
+
"entities"=>["comptes", "gram"],
|
24
|
+
"is_gadz"=>"true",
|
25
|
+
"gapps_id" => nil
|
26
|
+
}
|
27
|
+
|
28
|
+
attr_reader :attributes
|
29
|
+
|
30
|
+
def initialize(attr={},auth=nil)
|
31
|
+
@auth=auth
|
32
|
+
@attributes=attr
|
33
|
+
end
|
34
|
+
|
35
|
+
def uuid
|
36
|
+
@attributes["uuid"]
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.for(attr:{},auth: nil)
|
40
|
+
string_hash=attr.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}
|
41
|
+
self.new(DEFAULT_GRAM_ACCOUNT.merge(string_hash),auth)
|
42
|
+
end
|
43
|
+
|
44
|
+
def uri_for_get_request(with_password: false)
|
45
|
+
uri= "/api/v2/accounts/#{uuid}.json"
|
46
|
+
uri+= "?show_password_hash=true" if with_password
|
47
|
+
uri
|
48
|
+
end
|
49
|
+
|
50
|
+
def mock_get_request(with_password: false)
|
51
|
+
uri=uri_for_get_request(with_password: with_password)
|
52
|
+
ActiveResource::HttpMock.respond_to({},false) do |mock|
|
53
|
+
mock.get uri, {"Authorization"=>authorization_header,'Accept' => 'application/json'}, attributes.to_json, 200
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def mock_search_request_for(param,value=nil,response=[attributes])
|
58
|
+
value||=attributes[param.to_s]
|
59
|
+
value=URI.escape(URI.escape(value.to_s),"@")
|
60
|
+
response=response.to_json unless response.is_a? String
|
61
|
+
ActiveResource::HttpMock.respond_to({},false) do |mock|
|
62
|
+
mock.get "/api/v2/accounts.json?#{param.to_s}=#{value}", {"Authorization"=>authorization_header,'Accept' => 'application/json'}, response, 200
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def mock_put_request()
|
67
|
+
uri= "/api/v2/accounts/#{uuid}.json"
|
68
|
+
ActiveResource::HttpMock.respond_to({},false) do |mock|
|
69
|
+
mock.put uri, {"Authorization"=>authorization_header,'Content-Type' => 'application/json'}, attributes.to_json, 200
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.reset!
|
74
|
+
ActiveResource::HttpMock.reset!
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.http_basic_auth_header(user,password)
|
78
|
+
"Basic "+Base64.encode64("#{user}:#{password}").chomp
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def authorization_header
|
84
|
+
@auth
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gram_v2_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexandre Narbonne
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-03-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activeresource
|
@@ -25,6 +25,20 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '4.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: byebug
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '9.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '9.0'
|
28
42
|
- !ruby/object:Gem::Dependency
|
29
43
|
name: bundler
|
30
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,14 +95,17 @@ files:
|
|
81
95
|
- README.md
|
82
96
|
- Rakefile
|
83
97
|
- bin/console
|
98
|
+
- bin/env.rb
|
84
99
|
- bin/setup
|
85
100
|
- gram_v2_client.gemspec
|
86
101
|
- lib/gram_v2_client.rb
|
87
102
|
- lib/gram_v2_client/account.rb
|
88
103
|
- lib/gram_v2_client/base.rb
|
89
104
|
- lib/gram_v2_client/configuration.rb
|
105
|
+
- lib/gram_v2_client/exceptions.rb
|
90
106
|
- lib/gram_v2_client/group.rb
|
91
107
|
- lib/gram_v2_client/role.rb
|
108
|
+
- lib/gram_v2_client/rspec/gram_account_mocker.rb
|
92
109
|
- lib/gram_v2_client/version.rb
|
93
110
|
homepage: https://github.com/gadzorg/gram2_api_client_ruby
|
94
111
|
licenses:
|