granicus-platform-api 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- granicus-platform-api (0.1.3)
4
+ granicus-platform-api (0.1.4)
5
5
  hashie (~> 1.0.0)
6
6
  savon (~> 0.9.2)
7
7
 
@@ -79,26 +79,80 @@ module GranicusPlatformAPI
79
79
  self.classmap['VoteEntry'] = 'granicus:VoteEntry'
80
80
  self.classmap['VoteRecord'] = 'granicus:VoteRecord'
81
81
 
82
- # create a connected client
83
- def initialize(granicus_site,username,password,options={})
84
- # set things up
85
- @granicus_site = granicus_site
82
+ # create a client
83
+ def initialize(granicus_site=nil,username=nil,password=nil,options={})
84
+ # setup our private members
85
+ @options = options
86
+ @impersonation_token = nil
87
+ @connected = false
88
+
89
+ # configure savon
86
90
  Savon.configure do |config|
87
91
  config.log = false
88
92
  end
89
93
  HTTPI.log = false
94
+
95
+ # connect if we have a site and credentials
96
+ unless granicus_site.nil?
97
+ self.site = granicus_site
98
+ end
90
99
 
100
+ unless username.nil? or password.nil?
101
+ login(username,password)
102
+ end
103
+ end
104
+
105
+ # options
106
+ def options
107
+ @options
108
+ end
109
+ def options=(value)
110
+ @options = value
111
+ end
112
+
113
+ # connect up to a site
114
+ def connect(granicus_site,username,password,options={})
115
+ logout if @connected
116
+
91
117
  # create the client
118
+ site = granicus_site
119
+
120
+ # call login
121
+ login username, password
122
+ end
123
+
124
+ # site property
125
+ def site
126
+ return @granicus_site
127
+ end
128
+
129
+ def site=(value)
130
+ @granicus_site = value
92
131
  @client = Savon::Client.new do |wsdl, http|
93
132
  wsdl.document = File.expand_path("../granicus-platform-api.xml", __FILE__)
94
- wsdl.endpoint = "http://#{granicus_site}/SDK/User/index.php"
95
- http.proxy = options[:proxy] if not options[:proxy].nil?
133
+ wsdl.endpoint = "http://#{value}/SDK/User/index.php"
134
+ http.proxy = @options[:proxy] if not @options[:proxy].nil?
96
135
  end
136
+ end
137
+
138
+ # impersonate a user
139
+ def impersonate(token)
140
+ @impersonation_token = token
141
+ @client.http.headers["Cookie"] = "SESS1=#{token}; path=/"
142
+ end
143
+
144
+ def impersonation_token
145
+ @impersonation_token
146
+ end
97
147
 
98
- # call login
148
+ # login
149
+ def login(username,password)
150
+ logout if @connected
99
151
  call_soap_method(:login,'//ns4:LoginResponse/return',{'Username' => username, 'Password' => password})
152
+ @impersonation_token = @response.http.headers['Set-Cookie'].gsub(/SESS1=(.*); path=\//,'\\1')
153
+ @connected = true
100
154
  end
101
-
155
+
102
156
  # return the current logged on user name
103
157
  def get_current_user_logon
104
158
  call_soap_method(:get_current_user_logon,'//ns4:GetCurrentUserLogonResponse/Logon')
@@ -107,6 +161,7 @@ module GranicusPlatformAPI
107
161
  # logout
108
162
  def logout
109
163
  call_soap_method(:logout,'//ns4:LogoutResponse')
164
+ @connected = false
110
165
  end
111
166
 
112
167
  # return all of the cameras
@@ -227,7 +282,7 @@ module GranicusPlatformAPI
227
282
  #private
228
283
 
229
284
  def call_soap_method(method,returnfilter,args={},debug=false)
230
- response = @client.request :wsdl, method do
285
+ @response = @client.request :wsdl, method do
231
286
  soap.namespaces['xmlns:granicus'] = "http://granicus.com/xsd"
232
287
  soap.namespaces['xmlns:SOAP-ENC'] = "http://schemas.xmlsoap.org/soap/encoding/"
233
288
  soap.body = prepare_hash args
@@ -235,8 +290,8 @@ module GranicusPlatformAPI
235
290
  puts soap.body
236
291
  end
237
292
  end
238
-
239
- doc = Nokogiri::XML(response.to_xml) do |config|
293
+
294
+ doc = Nokogiri::XML(@response.to_xml) do |config|
240
295
  config.noblanks
241
296
  end
242
297
  response = handle_response(doc.xpath(returnfilter, doc.root.namespaces)[0])
@@ -1,3 +1,3 @@
1
1
  module GranicusPlatformAPI
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -24,6 +24,11 @@ describe GranicusPlatformAPI, "::Client.new" do
24
24
  logon = client.get_current_user_logon
25
25
  logon.should == GRANICUS_LOGIN
26
26
  end
27
+ it "should support impersonation" do
28
+ client2 = GranicusPlatformAPI::Client.new GRANICUS_SITE,nil,nil,{:proxy => 'http://localhost:8888' }
29
+ client2.impersonate client.impersonation_token
30
+ client2.get_current_user_logon.should == client.get_current_user_logon
31
+ end
27
32
  end
28
33
 
29
34
  describe GranicusPlatformAPI, "::Client Camera Methods" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: granicus-platform-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-06-28 00:00:00.000000000Z
12
+ date: 2011-06-29 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &2168580120 !ruby/object:Gem::Requirement
16
+ requirement: &2156236720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.6'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2168580120
24
+ version_requirements: *2156236720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: simplecov
27
- requirement: &2168579620 !ruby/object:Gem::Requirement
27
+ requirement: &2156236220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.4.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2168579620
35
+ version_requirements: *2156236220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hashie
38
- requirement: &2168579160 !ruby/object:Gem::Requirement
38
+ requirement: &2156235760 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2168579160
46
+ version_requirements: *2156235760
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: savon
49
- requirement: &2168578700 !ruby/object:Gem::Requirement
49
+ requirement: &2156235300 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.9.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2168578700
57
+ version_requirements: *2156235300
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: savon
60
- requirement: &2168578240 !ruby/object:Gem::Requirement
60
+ requirement: &2156234840 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.9.2
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2168578240
68
+ version_requirements: *2156234840
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: hashie
71
- requirement: &2168577780 !ruby/object:Gem::Requirement
71
+ requirement: &2156234380 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: 1.0.0
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *2168577780
79
+ version_requirements: *2156234380
80
80
  description: Wrapper for the Granicus Open Platform API v1.x
81
81
  email: javier@granicus.com
82
82
  executables: []