postini 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +12 -26
  3. data/README.txt +11 -4
  4. data/Rakefile +27 -4
  5. data/features/development.feature +13 -0
  6. data/features/step_definitions/common_steps.rb +172 -0
  7. data/features/support/common.rb +29 -0
  8. data/features/support/env.rb +6 -0
  9. data/features/support/matchers.rb +11 -0
  10. data/lib/postini/automated_batch_service.rb +464 -0
  11. data/lib/postini/configuration_check.rb +25 -0
  12. data/lib/postini/endpoint_resolver_service.rb +41 -0
  13. data/lib/postini/endpoints.rb +26 -0
  14. data/lib/postini/exceptions.rb +85 -0
  15. data/lib/postini.rb +74 -102
  16. data/script/console +1 -1
  17. data/script/txt2html +5 -16
  18. data/spec/exceptions_spec.rb +19 -0
  19. data/spec/postini_spec.rb +5 -38
  20. data/spec/rcov.opts +1 -0
  21. data/spec/spec_helper.rb +1 -1
  22. data/tasks/rspec.rake +1 -19
  23. data/vendor/automatedbatch.wsdl +1 -1
  24. metadata +21 -54
  25. data/config/hoe.rb +0 -76
  26. data/config/requirements.rb +0 -15
  27. data/lib/postini/api/automatedbatch/AutomatedBatch.rb +0 -1244
  28. data/lib/postini/api/automatedbatch/AutomatedBatchDriver.rb +0 -216
  29. data/lib/postini/api/automatedbatch/AutomatedBatchMappingRegistry.rb +0 -1883
  30. data/lib/postini/api/automatedbatch/AutomatedBatchServiceClient.rb +0 -523
  31. data/lib/postini/api/endpointresolver/EndpointResolver.rb +0 -121
  32. data/lib/postini/api/endpointresolver/EndpointResolverDriver.rb +0 -51
  33. data/lib/postini/api/endpointresolver/EndpointResolverMappingRegistry.rb +0 -268
  34. data/lib/postini/api/endpointresolver/EndpointResolverServiceClient.rb +0 -38
  35. data/lib/postini/api.rb +0 -8
  36. data/lib/postini/domain.rb +0 -72
  37. data/lib/postini/helpers/attributes.rb +0 -94
  38. data/lib/postini/helpers.rb +0 -13
  39. data/lib/postini/user.rb +0 -91
  40. data/lib/postini/users/aliases.rb +0 -55
  41. data/lib/postini/version.rb +0 -9
  42. data/spec/attribute_helper_spec.rb +0 -47
  43. data/spec/domain_spec.rb +0 -36
  44. data/spec/user_spec.rb +0 -142
  45. data/website/index.html +0 -89
  46. data/website/index.txt +0 -60
  47. data/website/javascripts/rounded_corners_lite.inc.js +0 -285
  48. data/website/spam_box.png +0 -0
  49. data/website/stylesheets/screen.css +0 -143
  50. data/website/template.html.erb +0 -56
@@ -1,51 +0,0 @@
1
- require File.dirname(__FILE__) + '/EndpointResolver.rb'
2
- require File.dirname(__FILE__) + '/EndpointResolverMappingRegistry.rb'
3
- require 'soap/rpc/driver'
4
-
5
- module Postini::API::EndpointResolver #:nodoc: all
6
-
7
- class EndpointResolverPort < ::SOAP::RPC::Driver
8
- DefaultEndpointUrl = "https://api-meta.postini.com/api2/endpointresolver"
9
-
10
- Methods = [
11
- [ "",
12
- "getServiceEndpoint",
13
- [ ["in", "parameters", ["::SOAP::SOAPElement", "http://postini.com/PSTN/SOAPAPI/v2/endpointresolver", "GetServiceEndpoint"]],
14
- ["out", "parameters", ["::SOAP::SOAPElement", "http://postini.com/PSTN/SOAPAPI/v2/endpointresolver", "GetServiceEndpointResponse"]] ],
15
- { :request_style => :document, :request_use => :literal,
16
- :response_style => :document, :response_use => :literal,
17
- :faults => {"Postini::API::EndpointResolver::UnknownInternalException"=>{:use=>"literal", :namespace=>nil, :name=>"UnknownInternalException", :encodingstyle=>"document", :ns=>"http://postini.com/PSTN/SOAPAPI/v2/endpointresolver"}, "Postini::API::EndpointResolver::AdminBlockException"=>{:use=>"literal", :namespace=>nil, :name=>"AdminBlockException", :encodingstyle=>"document", :ns=>"http://postini.com/PSTN/SOAPAPI/v2/endpointresolver"}, "Postini::API::EndpointResolver::MissingElementException"=>{:use=>"literal", :namespace=>nil, :name=>"MissingElementException", :encodingstyle=>"document", :ns=>"http://postini.com/PSTN/SOAPAPI/v2/endpointresolver"}, "Postini::API::EndpointResolver::InvalidValueException"=>{:use=>"literal", :namespace=>nil, :name=>"InvalidValueException", :encodingstyle=>"document", :ns=>"http://postini.com/PSTN/SOAPAPI/v2/endpointresolver"}, "Postini::API::EndpointResolver::UnknownEmailException"=>{:use=>"literal", :namespace=>nil, :name=>"UnknownEmailException", :encodingstyle=>"document", :ns=>"http://postini.com/PSTN/SOAPAPI/v2/endpointresolver"}, "Postini::API::EndpointResolver::MalformedKeyException"=>{:use=>"literal", :namespace=>nil, :name=>"MalformedKeyException", :encodingstyle=>"document", :ns=>"http://postini.com/PSTN/SOAPAPI/v2/endpointresolver"}, "Postini::API::EndpointResolver::InternalException"=>{:use=>"literal", :namespace=>nil, :name=>"InternalException", :encodingstyle=>"document", :ns=>"http://postini.com/PSTN/SOAPAPI/v2/endpointresolver"}, "Postini::API::EndpointResolver::NoSuchKeyException"=>{:use=>"literal", :namespace=>nil, :name=>"NoSuchKeyException", :encodingstyle=>"document", :ns=>"http://postini.com/PSTN/SOAPAPI/v2/endpointresolver"}} }
18
- ]
19
- ]
20
-
21
- def initialize(endpoint_url = nil)
22
- endpoint_url ||= DefaultEndpointUrl
23
- super(endpoint_url, nil)
24
- self.mapping_registry = EndpointResolverMappingRegistry::EncodedRegistry
25
- self.literal_mapping_registry = EndpointResolverMappingRegistry::LiteralRegistry
26
- init_methods
27
- end
28
-
29
- private
30
-
31
- def init_methods
32
- Methods.each do |definitions|
33
- opt = definitions.last
34
- if opt[:request_style] == :document
35
- add_document_operation(*definitions)
36
- else
37
- add_rpc_operation(*definitions)
38
- qname = definitions[0]
39
- name = definitions[2]
40
- if qname.name != name and qname.name.capitalize == name.capitalize
41
- ::SOAP::Mapping.define_singleton_method(self, qname.name) do |*arg|
42
- __send__(name, *arg)
43
- end
44
- end
45
- end
46
- end
47
- end
48
- end
49
-
50
-
51
- end
@@ -1,268 +0,0 @@
1
- require File.dirname(__FILE__) + '/EndpointResolver.rb'
2
- require 'soap/mapping'
3
-
4
- module Postini; module API; module EndpointResolver
5
-
6
- module EndpointResolverMappingRegistry
7
- EncodedRegistry = ::SOAP::Mapping::EncodedRegistry.new
8
- LiteralRegistry = ::SOAP::Mapping::LiteralRegistry.new
9
- NsEndpointresolver = "http://postini.com/PSTN/SOAPAPI/v2/endpointresolver"
10
-
11
- EncodedRegistry.register(
12
- :class => Postini::API::EndpointResolver::AdminBlockException,
13
- :schema_type => XSD::QName.new(NsEndpointresolver, "AdminBlockException"),
14
- :schema_element => [
15
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
16
- ]
17
- )
18
-
19
- EncodedRegistry.register(
20
- :class => Postini::API::EndpointResolver::GetServiceEndpoint,
21
- :schema_type => XSD::QName.new(NsEndpointresolver, "GetServiceEndpoint"),
22
- :schema_element => [
23
- ["apiKey", ["SOAP::SOAPString", XSD::QName.new(nil, "apiKey")]],
24
- ["email", ["SOAP::SOAPString", XSD::QName.new(nil, "email")]],
25
- ["service", ["Postini::API::EndpointResolver::Service", XSD::QName.new(nil, "service")]]
26
- ]
27
- )
28
-
29
- EncodedRegistry.register(
30
- :class => Postini::API::EndpointResolver::GetServiceEndpointResponse,
31
- :schema_type => XSD::QName.new(NsEndpointresolver, "GetServiceEndpointResponse"),
32
- :schema_element => [
33
- ["endpointURI", ["SOAP::SOAPString", XSD::QName.new(nil, "EndpointURI")], [0, 1]]
34
- ]
35
- )
36
-
37
- EncodedRegistry.register(
38
- :class => Postini::API::EndpointResolver::InternalException,
39
- :schema_type => XSD::QName.new(NsEndpointresolver, "InternalException"),
40
- :schema_element => [
41
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
42
- ]
43
- )
44
-
45
- EncodedRegistry.register(
46
- :class => Postini::API::EndpointResolver::InvalidValueException,
47
- :schema_type => XSD::QName.new(NsEndpointresolver, "InvalidValueException"),
48
- :schema_element => [
49
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
50
- ]
51
- )
52
-
53
- EncodedRegistry.register(
54
- :class => Postini::API::EndpointResolver::MalformedKeyException,
55
- :schema_type => XSD::QName.new(NsEndpointresolver, "MalformedKeyException"),
56
- :schema_element => [
57
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
58
- ]
59
- )
60
-
61
- EncodedRegistry.register(
62
- :class => Postini::API::EndpointResolver::MissingElementException,
63
- :schema_type => XSD::QName.new(NsEndpointresolver, "MissingElementException"),
64
- :schema_element => [
65
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
66
- ]
67
- )
68
-
69
- EncodedRegistry.register(
70
- :class => Postini::API::EndpointResolver::NoSuchKeyException,
71
- :schema_type => XSD::QName.new(NsEndpointresolver, "NoSuchKeyException"),
72
- :schema_element => [
73
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
74
- ]
75
- )
76
-
77
- EncodedRegistry.register(
78
- :class => Postini::API::EndpointResolver::UnknownEmailException,
79
- :schema_type => XSD::QName.new(NsEndpointresolver, "UnknownEmailException"),
80
- :schema_element => [
81
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
82
- ]
83
- )
84
-
85
- EncodedRegistry.register(
86
- :class => Postini::API::EndpointResolver::UnknownInternalException,
87
- :schema_type => XSD::QName.new(NsEndpointresolver, "UnknownInternalException"),
88
- :schema_element => [
89
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
90
- ]
91
- )
92
-
93
- EncodedRegistry.register(
94
- :class => Postini::API::EndpointResolver::Service,
95
- :schema_type => XSD::QName.new(NsEndpointresolver, "service")
96
- )
97
-
98
- LiteralRegistry.register(
99
- :class => Postini::API::EndpointResolver::AdminBlockException,
100
- :schema_type => XSD::QName.new(NsEndpointresolver, "AdminBlockException"),
101
- :schema_element => [
102
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
103
- ]
104
- )
105
-
106
- LiteralRegistry.register(
107
- :class => Postini::API::EndpointResolver::GetServiceEndpoint,
108
- :schema_type => XSD::QName.new(NsEndpointresolver, "GetServiceEndpoint"),
109
- :schema_element => [
110
- ["apiKey", ["SOAP::SOAPString", XSD::QName.new(nil, "apiKey")]],
111
- ["email", ["SOAP::SOAPString", XSD::QName.new(nil, "email")]],
112
- ["service", ["Postini::API::EndpointResolver::Service", XSD::QName.new(nil, "service")]]
113
- ]
114
- )
115
-
116
- LiteralRegistry.register(
117
- :class => Postini::API::EndpointResolver::GetServiceEndpointResponse,
118
- :schema_type => XSD::QName.new(NsEndpointresolver, "GetServiceEndpointResponse"),
119
- :schema_element => [
120
- ["endpointURI", ["SOAP::SOAPString", XSD::QName.new(nil, "EndpointURI")], [0, 1]]
121
- ]
122
- )
123
-
124
- LiteralRegistry.register(
125
- :class => Postini::API::EndpointResolver::InternalException,
126
- :schema_type => XSD::QName.new(NsEndpointresolver, "InternalException"),
127
- :schema_element => [
128
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
129
- ]
130
- )
131
-
132
- LiteralRegistry.register(
133
- :class => Postini::API::EndpointResolver::InvalidValueException,
134
- :schema_type => XSD::QName.new(NsEndpointresolver, "InvalidValueException"),
135
- :schema_element => [
136
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
137
- ]
138
- )
139
-
140
- LiteralRegistry.register(
141
- :class => Postini::API::EndpointResolver::MalformedKeyException,
142
- :schema_type => XSD::QName.new(NsEndpointresolver, "MalformedKeyException"),
143
- :schema_element => [
144
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
145
- ]
146
- )
147
-
148
- LiteralRegistry.register(
149
- :class => Postini::API::EndpointResolver::MissingElementException,
150
- :schema_type => XSD::QName.new(NsEndpointresolver, "MissingElementException"),
151
- :schema_element => [
152
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
153
- ]
154
- )
155
-
156
- LiteralRegistry.register(
157
- :class => Postini::API::EndpointResolver::NoSuchKeyException,
158
- :schema_type => XSD::QName.new(NsEndpointresolver, "NoSuchKeyException"),
159
- :schema_element => [
160
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
161
- ]
162
- )
163
-
164
- LiteralRegistry.register(
165
- :class => Postini::API::EndpointResolver::UnknownEmailException,
166
- :schema_type => XSD::QName.new(NsEndpointresolver, "UnknownEmailException"),
167
- :schema_element => [
168
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
169
- ]
170
- )
171
-
172
- LiteralRegistry.register(
173
- :class => Postini::API::EndpointResolver::UnknownInternalException,
174
- :schema_type => XSD::QName.new(NsEndpointresolver, "UnknownInternalException"),
175
- :schema_element => [
176
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
177
- ]
178
- )
179
-
180
- LiteralRegistry.register(
181
- :class => Postini::API::EndpointResolver::Service,
182
- :schema_type => XSD::QName.new(NsEndpointresolver, "service")
183
- )
184
-
185
- LiteralRegistry.register(
186
- :class => Postini::API::EndpointResolver::AdminBlockException,
187
- :schema_name => XSD::QName.new(NsEndpointresolver, "AdminBlockException"),
188
- :schema_element => [
189
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
190
- ]
191
- )
192
-
193
- LiteralRegistry.register(
194
- :class => Postini::API::EndpointResolver::GetServiceEndpoint,
195
- :schema_name => XSD::QName.new(NsEndpointresolver, "GetServiceEndpoint"),
196
- :schema_element => [
197
- ["apiKey", ["SOAP::SOAPString", XSD::QName.new(nil, "apiKey")]],
198
- ["email", ["SOAP::SOAPString", XSD::QName.new(nil, "email")]],
199
- ["service", ["Postini::API::EndpointResolver::Service", XSD::QName.new(nil, "service")]]
200
- ]
201
- )
202
-
203
- LiteralRegistry.register(
204
- :class => Postini::API::EndpointResolver::GetServiceEndpointResponse,
205
- :schema_name => XSD::QName.new(NsEndpointresolver, "GetServiceEndpointResponse"),
206
- :schema_element => [
207
- ["endpointURI", ["SOAP::SOAPString", XSD::QName.new(nil, "EndpointURI")], [0, 1]]
208
- ]
209
- )
210
-
211
- LiteralRegistry.register(
212
- :class => Postini::API::EndpointResolver::InternalException,
213
- :schema_name => XSD::QName.new(NsEndpointresolver, "InternalException"),
214
- :schema_element => [
215
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
216
- ]
217
- )
218
-
219
- LiteralRegistry.register(
220
- :class => Postini::API::EndpointResolver::InvalidValueException,
221
- :schema_name => XSD::QName.new(NsEndpointresolver, "InvalidValueException"),
222
- :schema_element => [
223
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
224
- ]
225
- )
226
-
227
- LiteralRegistry.register(
228
- :class => Postini::API::EndpointResolver::MalformedKeyException,
229
- :schema_name => XSD::QName.new(NsEndpointresolver, "MalformedKeyException"),
230
- :schema_element => [
231
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
232
- ]
233
- )
234
-
235
- LiteralRegistry.register(
236
- :class => Postini::API::EndpointResolver::MissingElementException,
237
- :schema_name => XSD::QName.new(NsEndpointresolver, "MissingElementException"),
238
- :schema_element => [
239
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
240
- ]
241
- )
242
-
243
- LiteralRegistry.register(
244
- :class => Postini::API::EndpointResolver::NoSuchKeyException,
245
- :schema_name => XSD::QName.new(NsEndpointresolver, "NoSuchKeyException"),
246
- :schema_element => [
247
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
248
- ]
249
- )
250
-
251
- LiteralRegistry.register(
252
- :class => Postini::API::EndpointResolver::UnknownEmailException,
253
- :schema_name => XSD::QName.new(NsEndpointresolver, "UnknownEmailException"),
254
- :schema_element => [
255
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
256
- ]
257
- )
258
-
259
- LiteralRegistry.register(
260
- :class => Postini::API::EndpointResolver::UnknownInternalException,
261
- :schema_name => XSD::QName.new(NsEndpointresolver, "UnknownInternalException"),
262
- :schema_element => [
263
- ["message", ["SOAP::SOAPString", XSD::QName.new(nil, "message")]]
264
- ]
265
- )
266
- end
267
-
268
- end; end; end
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/EndpointResolverDriver.rb'
3
-
4
-
5
- module Postini::API::EndpointResolver
6
-
7
- endpoint_url = ARGV.shift
8
- obj = EndpointResolverPort.new(endpoint_url)
9
-
10
- # run ruby with -d to see SOAP wiredumps.
11
- obj.wiredump_dev = STDERR if $DEBUG
12
-
13
- # SYNOPSIS
14
- # GetServiceEndpoint(parameters)
15
- #
16
- # ARGS
17
- # parameters GetServiceEndpoint - {http://postini.com/PSTN/SOAPAPI/v2/endpointresolver}GetServiceEndpoint
18
- #
19
- # RETURNS
20
- # parameters GetServiceEndpointResponse - {http://postini.com/PSTN/SOAPAPI/v2/endpointresolver}GetServiceEndpointResponse
21
- #
22
- # RAISES
23
- # fault AdminBlockException - {http://postini.com/PSTN/SOAPAPI/v2/endpointresolver}AdminBlockException
24
- # fault InternalException - {http://postini.com/PSTN/SOAPAPI/v2/endpointresolver}InternalException
25
- # fault InvalidValueException - {http://postini.com/PSTN/SOAPAPI/v2/endpointresolver}InvalidValueException
26
- # fault MalformedKeyException - {http://postini.com/PSTN/SOAPAPI/v2/endpointresolver}MalformedKeyException
27
- # fault MissingElementException - {http://postini.com/PSTN/SOAPAPI/v2/endpointresolver}MissingElementException
28
- # fault NoSuchKeyException - {http://postini.com/PSTN/SOAPAPI/v2/endpointresolver}NoSuchKeyException
29
- # fault UnknownEmailException - {http://postini.com/PSTN/SOAPAPI/v2/endpointresolver}UnknownEmailException
30
- # fault UnknownInternalException - {http://postini.com/PSTN/SOAPAPI/v2/endpointresolver}UnknownInternalException
31
- #
32
- parameters = nil
33
- puts obj.getServiceEndpoint(parameters)
34
-
35
-
36
-
37
-
38
- end
data/lib/postini/api.rb DELETED
@@ -1,8 +0,0 @@
1
- module Postini
2
-
3
- # This module contains all the wsdl2ruby uglies and is not documented, since
4
- # this gem is supposed to abstract it away
5
- module API #:nodoc: all
6
-
7
- end
8
- end
@@ -1,72 +0,0 @@
1
- require 'postini/api/automatedbatch/AutomatedBatchDriver'
2
-
3
- module Postini
4
-
5
- # Represents the functions to perform on a domain
6
- #
7
- # TODO: Definitely improve this documentation
8
- class Domain
9
-
10
- attr_accessor :id, :name, :org, :substrip
11
-
12
- class << self
13
-
14
- # Return an instance of #Domain with all the attributes populated
15
- def find( domain )
16
- remote = automated_batch_port
17
- request = Postini::API::AutomatedBatch::Displaydomain.new( Postini.auth, domain )
18
- response = remote.displaydomain( request )
19
- domain_record = response.domainRecord
20
-
21
- # Don't give back false positives
22
- if domain_record.domainid == ""
23
- return nil
24
- end
25
-
26
- new(
27
- :name => domain_record.domainname,
28
- :id => domain_record.domainid,
29
- :org => domain_record.org,
30
- :substrip => domain_record.substrip
31
- )
32
- end
33
-
34
- # Return a remote port with debug enabled if required
35
- def automated_batch_port #:nodoc:
36
- remote = Postini::API::AutomatedBatch::AutomatedBatchPort.new( Postini.endpoint_uri )
37
- remote.wiredump_dev = Postini.soap4r_wiredump_dev if Postini.soap4r_wiredump?
38
- remote
39
- end
40
- end
41
-
42
- # Setup a new instance with the combination of attributes set
43
- def initialize( attributes = {} )
44
- attributes.each_pair do |k,v|
45
- instance_variable_set "@#{k.to_s}", v
46
- end
47
- end
48
-
49
- def new?
50
- @id.nil?
51
- end
52
-
53
- # Create a new domain in the system. Requires +name+ and +org+ to be set.
54
- # This method will through a SOAP exception if the domain could not be
55
- # added.
56
- def create
57
- return false unless new?
58
-
59
- # TODO: Add improved validations here
60
- return false if @name.nil? || @org.nil?
61
-
62
- remote = self.class.automated_batch_port
63
- args = Postini::API::AutomatedBatch::Adddomainargs.new( @name )
64
- request = Postini::API::AutomatedBatch::Adddomain.new(
65
- Postini.auth, @org, args
66
- )
67
- remote.adddomain( request )
68
- end
69
-
70
- end
71
-
72
- end
@@ -1,94 +0,0 @@
1
- module Postini
2
- module Helpers
3
- # Provide our classes with ActiveRecord like attribute handling, mapping
4
- # plain text to native Ruby objects (and vice versa).
5
- module Attributes
6
-
7
- def self.included( base ) #:nodoc:
8
- base.extend( ClassMethods )
9
- base.send( :include, InstanceMethods )
10
- end
11
-
12
- module ClassMethods
13
-
14
- def self.extended( base )
15
- base.send( :class_inheritable_hash, :attributes )
16
- base.attributes = {}
17
- end
18
-
19
- # Specifies the list of attributes for the class, together with an
20
- # optional type to map them to.
21
- #
22
- # has_attributes :address
23
- # has_attributes :active, :welcome, :type => :boolean
24
- #
25
- def has_attributes( *args )
26
- opts = args.extract_options!
27
- opts[:type] ||= :string
28
-
29
- args.each do |attr|
30
- register_attribute( attr => opts[:type] )
31
- end
32
- end
33
-
34
- # Specify a single attribute together with its type
35
- def has_attribute( attr )
36
- raise "Invalid parameter, hash expected" unless attr.is_a?( Hash ) &&
37
- attr.keys.size == 1
38
-
39
- register_attribute( attr )
40
- end
41
-
42
- private
43
-
44
- # Register an attribute in our internal list
45
- def register_attribute( attr )
46
- self.attributes.merge!( attr.stringify_keys! )
47
-
48
- # :id needs to be handled specialy
49
- if attr.keys.first == "id"
50
- class_eval <<-EOF
51
- def id
52
- @attributes[ "id" ]
53
- end
54
- def id=( value )
55
- @attributes[ "id" ] = value
56
- end
57
- EOF
58
- end
59
- end
60
-
61
- end
62
-
63
- module InstanceMethods
64
-
65
- # Setup a new instance with all the attributes configured
66
- def initialize( attributes = {} )
67
- validate_attributes!( attributes )
68
-
69
- @attributes = attributes.stringify_keys
70
- end
71
-
72
- def method_missing( method_name, *args )
73
- method_name.to_s =~ /^([^=]+)(\=)?$/
74
- key = $1.to_s
75
- if self.class.attributes.has_key?( key )
76
- if $2
77
- @attributes[ key ] = *args
78
- else
79
- @attributes[ key ]
80
- end
81
- end
82
- end
83
-
84
- private
85
-
86
- def validate_attributes!( attrs = {} )
87
- attrs.assert_valid_keys( self.class.attributes.symbolize_keys.keys )
88
- end
89
-
90
- end
91
-
92
- end
93
- end
94
- end
@@ -1,13 +0,0 @@
1
- require 'activesupport'
2
- require 'postini/helpers/attributes'
3
-
4
- module Postini
5
-
6
- # A collection of helpers to implement various needed convenience methods
7
- # to our other classes and to keep things DRY. The behaviour is very much
8
- # based on, and inspired by, ActiveRecord and makes excessive use of
9
- # ActiveSupport to reach its goals.
10
- module Helpers
11
-
12
- end
13
- end
data/lib/postini/user.rb DELETED
@@ -1,91 +0,0 @@
1
- require 'postini/api/automatedbatch/AutomatedBatchDriver'
2
- require 'postini/users/aliases'
3
-
4
- module Postini
5
-
6
- # This class represents a user in the Postini systems.
7
- #
8
- # TODO: Expand documentation
9
- class User
10
-
11
- include Helpers::Attributes
12
-
13
- has_attributes :id, :message_count, :message_limit, :orgid, :create_method,
14
- :virus_notify, :type => :int
15
- has_attributes :active, :junkmail_filter, :message_encryption,
16
- :message_limited, :virus_state, :weblocked, :welcome_count,
17
- :wireless_state, :type => :bool
18
- has_attributes :address, :notice_address, :initial_password, :password,
19
- :lang_locale, :timezone, :orgtag, :ext_encrypt
20
- has_attributes :approved_recipients, :approved_senders, :blocked_senders,
21
- :type => :array
22
- has_attributes :created_date, :lastmod_date, :type => :timestamp
23
- has_attributes :filter_adult, :filter_bulk, :filter_getrich,
24
- :filter_offers, :filter_racial, :type => :filter
25
-
26
- include Users::Aliases
27
-
28
- class << self
29
-
30
- # Return a new instance of the user
31
- # TODO: Make this take various options just like ActiveRecord
32
- def find( user )
33
- remote = automated_batch_port( user )
34
- request = Postini::API::AutomatedBatch::Displayuser.new( Postini.auth, user )
35
- response = remote.displayuser( request )
36
- user_record = response.userRecord
37
-
38
- attributes = {}
39
- user_record.instance_variables.each do |var|
40
- attributes[ var.sub('@','').to_sym ] = user_record.instance_variable_get(var)
41
- end
42
-
43
- # fix id
44
- attributes[:id] = attributes.delete(:user_id)
45
-
46
- new( attributes )
47
- end
48
-
49
- # Permanently remove the user from Postini
50
- def destroy( address )
51
- remote = automated_batch_port( address )
52
- request = Postini::API::AutomatedBatch::Deleteuser.new( Postini.auth, address )
53
- remote.deleteuser( request )
54
- end
55
-
56
- # Return a remote port for the address, with debug enabled if required
57
- def automated_batch_port( address = nil ) #:nodoc:
58
- remote = Postini::API::AutomatedBatch::AutomatedBatchPort.new( Postini.endpoint_uri( address ) )
59
- remote.wiredump_dev = Postini.soap4r_wiredump_dev if Postini.soap4r_wiredump?
60
- remote
61
- end
62
-
63
- end
64
-
65
- def new?
66
- self.id.nil?
67
- end
68
-
69
- # Create the new user. Pass +welcome+ as '1' to have a welcome mail sent
70
- # to the user. The org for the user will be pulled from the org attribute
71
- def create( welcome = 0 )
72
- return false unless new?
73
-
74
- # TODO: Add missing validations here
75
- return false if self.address.nil? || self.orgid.nil?
76
-
77
- remote = self.class.automated_batch_port
78
- args = Postini::API::AutomatedBatch::Adduserargs.new( self.orgid, welcome )
79
- request = Postini::API::AutomatedBatch::Adduser.new( Postini.auth, self.address, args )
80
- remote.adduser( request )
81
- end
82
-
83
- # Remove the user from Postini
84
- def destroy
85
- return false if new?
86
-
87
- self.class.destroy( self.address )
88
- end
89
-
90
- end
91
- end