Class: Gharpay::Base
Instance Method Summary collapse
-
#cancel_order(cancel_order) ⇒ Object
This method cancels the complete order.
-
#city_list ⇒ Object
This method returns a list of cities currently being served by Gharpay in an array.
-
#create_order(order) ⇒ Object
Creates order with Gharpay.
-
#initialize(username, password) ⇒ Base
constructor
A new instance of Base.
-
#pincodes_in_city(city) ⇒ Object
This method returns a list of pincodes in a city in an array.
-
#valid_pincode?(zip) ⇒ Boolean
Validates whether the location with this pincode is serviced by Gharpay.
-
#view_details(order_id) ⇒ Object
TODO: check output.
-
#view_order_status(order_id) ⇒ Object
This method returns the status of the order.
Constructor Details
#initialize(username, password) ⇒ Base
Returns a new instance of Base.
12 13 14 15 |
# File 'lib/gharpay/api.rb', line 12 def initialize(username, password) @creds = {"username" => username, "password" => password } puts @creds end |
Instance Method Details
#cancel_order(cancel_order) ⇒ Object
This method cancels the complete order.
45 46 47 48 49 50 51 52 |
# File 'lib/gharpay/api.rb', line 45 def cancel_order(cancel_order) = {:body => cancel_order.to_xml(:root => "cancelOrder"), :headers => @creds.merge('Content-Type' => 'application/xml')} res = self.class.post("/cancelOrder", ) return res['cancelOrderResponse']['result'] unless res['cancelOrderResponse']['errorMessage'] res['cancelOrderResponse']['errorMessage'] rescue return false end |
#city_list ⇒ Object
This method returns a list of cities currently being served by Gharpay in an array
72 73 74 75 76 77 |
# File 'lib/gharpay/api.rb', line 72 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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gharpay/api.rb', line 28 def create_order(order) = {:body => order.to_xml(:root => "transaction"), :headers => @creds.merge('Content-Type' => 'application/xml')} res = self.class.post("/createOrder", ) return_val=Hash.new if res['createOrderResponse']['orderID'] return_val["status"]=true return_val["orderID"]=res['createOrderResponse']['orderID'] else return_val["status"]=false return_val["error"]=res['createOrderResponse']['errorMessage'] end return return_val rescue return nil end |
#pincodes_in_city(city) ⇒ Object
This method returns a list of pincodes in a city in an array
80 81 82 83 84 85 86 |
# File 'lib/gharpay/api.rb', line 80 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
18 19 20 21 22 23 24 25 |
# File 'lib/gharpay/api.rb', line 18 def valid_pincode?(zip) res = self.class.get("/isPincodePresent", :query => {:pincode => zip}, :headers => @creds) puts res eval(res['isPincodePresentPresentResponse']['result']) rescue return false end |
#view_details(order_id) ⇒ Object
TODO: check output
55 56 57 58 59 60 61 |
# File 'lib/gharpay/api.rb', line 55 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
64 65 66 67 68 69 |
# File 'lib/gharpay/api.rb', line 64 def view_order_status(order_id) res = self.class.get("/viewOrderStatus", :query => {:orderID => order_id}, :headers => @creds) res['viewOrderStatusResponse']['orderStatus'] rescue return nil end |