Class: Resource
- Inherits:
-
Object
- Object
- Resource
- Defined in:
- lib/resource.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
-
#create_resource_once ⇒ Object
Purpose: Create service requests URL: [API endpoint]/requests. Sample URL: api.city.gov/dev/v2/requests.xml Format sent: Content-Type: application/x-www-form-urlencoded Formats returned: XML (JSON available if denoted by Service Discovery) HTTP Method: POST Requires API Key: Yes.
- #data_from_options ⇒ Object
- #definition_resource ⇒ Object
- #discovery_url ⇒ Object
- #first_service_code ⇒ Object
- #get_next ⇒ Object
-
#initialize(session, options) ⇒ Resource
constructor
A new instance of Resource.
- #services_resource ⇒ Object
Constructor Details
#initialize(session, options) ⇒ Resource
Returns a new instance of Resource.
6 7 8 9 10 |
# File 'lib/resource.rb', line 6 def initialize(session,) = @session = session @last_resource = session.resource end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/resource.rb', line 4 def end |
#raw ⇒ Object
Returns the value of attribute raw.
4 5 6 |
# File 'lib/resource.rb', line 4 def raw @raw end |
Instance Method Details
#create_resource_once ⇒ Object
Purpose: Create service requests URL: [API endpoint]/requests. Sample URL: api.city.gov/dev/v2/requests.xml Format sent: Content-Type: application/x-www-form-urlencoded Formats returned: XML (JSON available if denoted by Service Discovery) HTTP Method: POST Requires API Key: Yes
Required Arguments jurisdiction_id service_code (obtained from GET Service List method) location: either lat & long or address_string or address_id must be submitted attribute - only required if the service_code requires a service definition with required fields Explanation: An array of key/value responses based on Service Definitions. This takes the form of attribute=value where multiple code/value pairs can be specified as well as multiple values for the same code in the case of a multivaluelist datatype (attribute[]=value1&attribute[]=value2&attribute[]=value3) - see example
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/resource.rb', line 60 def create_resource_once @raw.xml = [] @raw.json = [] # For each endpoint... @session.discovery.xml.response.discovery.endpoints.endpoint.each do |endpoint| next if type(endpoint) == 'production' and !.production @raw.xml << Client.new.post("#{endpoint.url}/requests.xml",) end @session.discovery.json.response.endpoints.each do |endpoint| next if type(endpoint) == 'production' and !.production @raw.json << Client.new.post("#{endpoint.url}/requests.json",) end if .json @raw. = @raw end |
#data_from_options ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/resource.rb', line 78 def ## Converting @options back to a hash and merge them with user-supplied # post data. { :api_key => .api_key, :jurisdiction_id => .jurisdiction_id, :service_code => first_service_code, :address_string => .address }.merge!(.post) end |
#definition_resource ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/resource.rb', line 31 def definition_resource @raw = [] @session.raw_services.each do |raw_service| raw_service.response.each do |service| next if !service. or service. == 'false' response = Client.new(raw_service.base,raw_service.format) response.get_and_unwrap("/services/#{service.service_code}.#{raw_service.format}?jurisdiction_id=#{@options[:jurisdiction_id]}",'') @raw << response end end end |
#discovery_url ⇒ Object
16 17 18 19 20 |
# File 'lib/resource.rb', line 16 def discovery_url @raw = OpenStruct.new @raw.json = Client.new([:discovery_url],'json').get(".json") @raw.xml = Client.new([:discovery_url],'xml').get(".xml") end |
#first_service_code ⇒ Object
88 89 90 |
# File 'lib/resource.rb', line 88 def first_service_code @session.resources[1].xml.first.response.services.service.service_code end |
#get_next ⇒ Object
12 13 14 |
# File 'lib/resource.rb', line 12 def get_next self.send [:with] end |
#services_resource ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/resource.rb', line 22 def services_resource @raw = [] @session.endpoint_array.each do |endpoint| response = Client.new(endpoint[0],endpoint[1]) response.get_and_unwrap("/services.#{endpoint[1]}?jurisdiction_id=#{@options[:jurisdiction_id]}",'services.service') @raw << response end end |