Class: Moo::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/moo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#error_codeObject

Returns the value of attribute error_code.



33
34
35
# File 'lib/moo.rb', line 33

def error_code
  @error_code
end

#error_stringObject

Returns the value of attribute error_string.



33
34
35
# File 'lib/moo.rb', line 33

def error_string
  @error_string
end

#raw_responseObject

Returns the value of attribute raw_response.



33
34
35
# File 'lib/moo.rb', line 33

def raw_response
  @raw_response
end

#session_idObject

Returns the value of attribute session_id.



33
34
35
# File 'lib/moo.rb', line 33

def session_id
  @session_id
end

#start_urlObject

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_versionObject



12
13
14
# File 'lib/moo.rb', line 12

def api_version
  0.7
end

#default_optionsObject



16
17
18
19
20
21
# File 'lib/moo.rb', line 16

def default_options
  {
    :designs => [],
    :api_key => 0
  }
end

#error?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/moo.rb', line 53

def error?
  @error ||= (@response.search('error').inner_html == "true")
end

#process_responseObject



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_typeObject



23
24
25
# File 'lib/moo.rb', line 23

def product_type
  @designs.first.product_type if @designs.first
end

#submitObject



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.expand_path(File.dirname(__FILE__) + "/template.xml.builder")).read
  xml.target!
end