Class: Gharpay::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/gharpay/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Base

Returns a new instance of Base.



8
9
10
# File 'lib/gharpay/api.rb', line 8

def initialize(username, password)
  @creds = {"username" => username, "password" => password }
end

Instance Method Details

#cancel_order(cancel_order) ⇒ Object

This method cancels the complete order.



31
32
33
34
35
36
37
38
# File 'lib/gharpay/api.rb', line 31

def cancel_order(cancel_order)
  options = {:body => cancel_order.to_xml(:root => "cancelOrder"), :headers => @creds.merge('Content-Type' => 'application/xml')}
  res = self.class.post("/cancelOrder", options)
  return res['cancelOrderResponse']['result'] unless res['cancelOrderResponse']['errorMessage']
  res['cancelOrderResponse']['errorMessage']
rescue
  return false
end

#city_listObject

This method returns a list of cities currently being served by Gharpay in an array



58
59
60
61
62
63
# File 'lib/gharpay/api.rb', line 58

def city_list
  res = self.class.get("/getCityList", :headers => @creds)
  res['getCityListResponse']['city']
rescue
  return nil  
end

#create_order(order) ⇒ Object

Creates order with Gharpay



21
22
23
24
25
26
27
28
# File 'lib/gharpay/api.rb', line 21

def create_order(order) 
  options = {:body => order.to_xml(:root => "transaction"), :headers => @creds.merge('Content-Type' => 'application/xml')}
  res = self.class.post("/createOrder", options)
  return res['createOrderResponse']['orderID'] unless res['createOrderResponse']['errorMessage']
  res['createOrderResponse']['errorMessage']
rescue
  return nil 
end

#pincodes_in_city(city) ⇒ Object

This method returns a list of pincodes in a city in an array



66
67
68
69
70
71
72
# File 'lib/gharpay/api.rb', line 66

def pincodes_in_city(city)
  res = self.class.get("/getPincodesInCity", :query => {:cityName => city}, :headers => @creds)
  return res['getPincodesInCityResponse']['pincode'] unless res['getPincodesInCityResponse']['errorMessage']
  res['getPincodesInCityResponse']['errorMessage']
rescue
  return nil
end

#valid_pincode?(zip) ⇒ Boolean

Validates whether the location with this pincode is serviced by Gharpay

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/gharpay/api.rb', line 13

def valid_pincode?(zip)
  res = self.class.get("/isPincodePresent", :query => {:pincode => zip}, :headers => @creds)
  eval(res['isPincodePresentPresentResponse']['result'])
rescue 
  return false
end

#view_details(order_id) ⇒ Object

TODO: check output



41
42
43
44
45
46
47
# File 'lib/gharpay/api.rb', line 41

def view_details(order_id)
  res = self.class.get("/viewOrderDetails", :query => {:orderID => order_id}, :headers => @creds)
  res['viewOrderDetailsResponse'] unless res['viewOrderDetailsResponse']['errorMessage']
  res['viewOrderDetailsResponse']['errorMessage']
rescue
  return nil  
end

#view_order_status(order_id) ⇒ Object

This method returns the status of the order



50
51
52
53
54
55
# File 'lib/gharpay/api.rb', line 50

def view_order_status(order_id)
  res = self.class.get("/viewOrderStatus", :query => {:orderID => order_id}, :headers => @creds)
  res['viewOrderStatusResponse']['orderStatus']
rescue
  return nil
end