Class: Moo::Order
- Inherits:
-
Object
- Object
- Moo::Order
- Defined in:
- lib/moo.rb
Instance Attribute Summary collapse
-
#error_code ⇒ Object
Returns the value of attribute error_code.
-
#error_string ⇒ Object
Returns the value of attribute error_string.
-
#raw_response ⇒ Object
Returns the value of attribute raw_response.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#start_url ⇒ Object
Returns the value of attribute start_url.
Instance Method Summary collapse
- #api_version ⇒ Object
- #default_options ⇒ Object
- #error? ⇒ Boolean
- #process_response ⇒ Object
- #product_type ⇒ Object
- #submit ⇒ Object
- #to_xml(xml = nil) ⇒ Object
Instance Attribute Details
#error_code ⇒ Object
Returns the value of attribute error_code.
33 34 35 |
# File 'lib/moo.rb', line 33 def error_code @error_code end |
#error_string ⇒ Object
Returns the value of attribute error_string.
33 34 35 |
# File 'lib/moo.rb', line 33 def error_string @error_string end |
#raw_response ⇒ Object
Returns the value of attribute raw_response.
33 34 35 |
# File 'lib/moo.rb', line 33 def raw_response @raw_response end |
#session_id ⇒ Object
Returns the value of attribute session_id.
33 34 35 |
# File 'lib/moo.rb', line 33 def session_id @session_id end |
#start_url ⇒ Object
Returns the value of attribute start_url.
33 34 35 |
# File 'lib/moo.rb', line 33 def start_url @start_url end |
Instance Method Details
#api_version ⇒ Object
12 13 14 |
# File 'lib/moo.rb', line 12 def api_version 0.7 end |
#default_options ⇒ Object
16 17 18 19 20 21 |
# File 'lib/moo.rb', line 16 def { :designs => [], :api_key => 0 } end |
#error? ⇒ Boolean
53 54 55 |
# File 'lib/moo.rb', line 53 def error? @error ||= (@response.search('error').inner_html == "true") end |
#process_response ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/moo.rb', line 42 def process_response @response = Hpricot(raw_response) if error? @error_string = @response.search('error_string').inner_html @error_code = @response.search('error_code').inner_html else @session_id = @response.search('session_id').inner_html @start_url = @response.search('start_url').inner_html end end |
#product_type ⇒ Object
23 24 25 |
# File 'lib/moo.rb', line 23 def product_type @designs.first.product_type if @designs.first end |
#submit ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/moo.rb', line 34 def submit res = Net::HTTP.post_form(URI.parse('http://www.moo.com/api/api.php'), {'xml'=>self.to_xml, 'method'=>'direct'}) @raw_response = res.body process_response !error? end |
#to_xml(xml = nil) ⇒ Object
27 28 29 30 31 |
# File 'lib/moo.rb', line 27 def to_xml(xml=nil) xml = Builder::XmlMarkup.new(:target => (@xml_string = "")) unless xml eval File.open(File.(File.dirname(__FILE__) + "/template.xml.builder")).read xml.target! end |