Class: ConstantContact::Base
- Inherits:
-
ActiveResource::Base
- Object
- ActiveResource::Base
- ConstantContact::Base
- Defined in:
- lib/constantcontact/base.rb
Direct Known Subclasses
Activity, Campaign, CampaignEvents::Base, CampaignSchedule, Contact, ContactEvents::Base, ContactList, ContactListMember, EmailAddress
Constant Summary
- DATE_FORMAT =
"%Y-%m-%dT%H:%M:%SZ"
Class Method Summary (collapse)
-
+ (Object) api_key
Gets the api_key for REST HTTP authentication.
-
+ (Object) api_key=(api_key)
Sets the api_key for REST HTTP authentication.
- + (Object) collection_path(prefix_options = {}, query_options = nil)
-
+ (Object) connection(refresh = false)
An instance of ActiveResource::Connection that is the base connection to the remote service.
- + (Object) element_path(id, prefix_options = {}, query_options = nil)
-
+ (Object) parse_id(url)
Returns an integer which can be used in #find calls.
Instance Method Summary (collapse)
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method_symbol, *arguments, &block) (protected)
support underscore accessors to CamelCase the attributes hash
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/constantcontact/base.rb', line 147 def method_missing(method_symbol, *arguments, &block) #:nodoc: method_name = method_symbol.to_s if method_name =~ /(=|\?)$/ case $1 when "=" attributes[search_attributes($`)] = arguments.first when "?" attributes[search_attributes($`)] end else key = search_attributes(method_name) return attributes[key] if attributes.has_key?(key) super end end |
Class Method Details
+ (Object) api_key
Gets the api_key for REST HTTP authentication.
32 33 34 35 36 37 38 39 |
# File 'lib/constantcontact/base.rb', line 32 def api_key # Not using superclass_delegating_reader. See +site+ for explanation if defined?(@api_key) @api_key elsif superclass != Object && superclass.api_key superclass.api_key.dup.freeze end end |
+ (Object) api_key=(api_key)
Sets the api_key for REST HTTP authentication.
42 43 44 45 |
# File 'lib/constantcontact/base.rb', line 42 def api_key=(api_key) @connection = nil @api_key = api_key end |
+ (Object) collection_path(prefix_options = {}, query_options = nil)
65 66 67 68 69 |
# File 'lib/constantcontact/base.rb', line 65 def collection_path( = {}, = nil) () , = () if .nil? "/ws/customers/#{self.user}#{prefix()}#{collection_name}#{query_string()}" end |
+ (Object) connection(refresh = false)
An instance of ActiveResource::Connection that is the base connection to the remote service. The refresh parameter toggles whether or not the connection is refreshed at every request or not (defaults to false).
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/constantcontact/base.rb', line 50 def connection(refresh = false) if defined?(@connection) || superclass == Object @connection = ActiveResource::Connection.new(site, format) if refresh || @connection.nil? @connection.proxy = proxy if proxy @connection.user = "#{api_key}%#{user}" if user @connection.password = password if password @connection.auth_type = auth_type if auth_type @connection.timeout = timeout if timeout @connection. = if @connection else superclass.connection end end |
+ (Object) element_path(id, prefix_options = {}, query_options = nil)
78 79 80 81 82 83 84 |
# File 'lib/constantcontact/base.rb', line 78 def element_path(id, = {}, = nil) , = () if .nil? integer_id = parse_id(id) id_val = integer_id.zero? ? nil : "/#{integer_id}" #"#{collection_path}#{id_val}#{query_string(query_options)}" "/ws/customers/#{self.user}#{prefix()}#{collection_name}/#{URI.parser.escape id.to_s}#{query_string()}" end |
+ (Object) parse_id(url)
Returns an integer which can be used in #find calls. Assumes url structure with the id at the end, e.g.:
http://api.constantcontact.com/ws/customers/yourname/contacts/29
74 75 76 |
# File 'lib/constantcontact/base.rb', line 74 def parse_id(url) url.to_s.split('/').last.to_i end |
Instance Method Details
- (Object) to_atom(options = {})
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/constantcontact/base.rb', line 6 def to_atom(={}) "<entry xmlns=\"http://www.w3.org/2005/Atom\"> <title type=\"text\"> </title> <updated>#{Time.now.strftime(DATE_FORMAT)}</updated> <author></author> <id>#{id.blank? ? 'data:,none' : id}</id> <summary type=\"text\">#{self.class.name.split('::').last}</summary> <content type=\"application/vnd.ctct+xml\"> #{self.to_xml} </content> </entry>" end |