Class: AruxApp::API::Cart
- Inherits:
-
Object
- Object
- AruxApp::API::Cart
- Defined in:
- lib/arux_app/api/cart.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#auth ⇒ Object
Returns the value of attribute auth.
Class Method Summary collapse
Instance Method Summary collapse
- #add_item(params) ⇒ Object
- #api_uri ⇒ Object
- #create(params) ⇒ Object
- #delete_item(item_identifier) ⇒ Object
- #destroy(uuid) ⇒ Object
- #get(uuid = nil) ⇒ Object
- #get_item(item_identifier) ⇒ Object
- #get_items ⇒ Object
- #get_status ⇒ Object
-
#initialize(options = {}) ⇒ Cart
constructor
A new instance of Cart.
- #public_uri ⇒ Object
- #update_item(item_identifier, params) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Cart
Returns a new instance of Cart.
6 7 8 9 10 11 12 |
# File 'lib/arux_app/api/cart.rb', line 6 def initialize( = {}) self.access_token = [:access_token] self.auth = self.access_token.auth raise API::InitializerError.new(:access_token, "can't be blank") if self.access_token.nil? raise API::InitializerError.new(:access_token, "must be of class type AruxApp::API::Auth::AccessToken") if !self.access_token.is_a?(AruxApp::API::Auth::AccessToken) end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
4 5 6 |
# File 'lib/arux_app/api/cart.rb', line 4 def access_token @access_token end |
#auth ⇒ Object
Returns the value of attribute auth.
4 5 6 |
# File 'lib/arux_app/api/cart.rb', line 4 def auth @auth end |
Class Method Details
Instance Method Details
#add_item(params) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/arux_app/api/cart.rb', line 98 def add_item(params) path = %(/api/#{self.generate_cart_path}/items) request = HTTPI::Request.new request.url = "#{api_uri}#{path}" if params.keys.first.to_s != 'item' params = {:item => params} end request.body = params.to_json request.headers = self.generate_headers response = HTTPI.post(request) if !response.error? JSON.parse(response.body) else raise(API::Error.new(response.code, JSON.parse(response.body)["message"])) end end |
#api_uri ⇒ Object
26 27 28 |
# File 'lib/arux_app/api/cart.rb', line 26 def api_uri self.class.api_uri end |
#create(params) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/arux_app/api/cart.rb', line 169 def create(params) path = "/api/#{self.generate_cart_path}/carts" request = HTTPI::Request.new request.url = "#{api_uri}#{path}" request.headers = self.generate_headers request.body = params.to_json response = HTTPI.post(request) if !response.error? JSON.parse(response.body) else raise(API::Error.new(response.code, JSON.parse(response.body)["message"])) end end |
#delete_item(item_identifier) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/arux_app/api/cart.rb', line 138 def delete_item(item_identifier) path = %(/api/#{self.generate_cart_path}/items/#{AruxApp::API.uri_escape(item_identifier)}) request = HTTPI::Request.new request.url = "#{api_uri}#{path}" request.headers = self.generate_headers response = HTTPI.delete(request) if !response.error? JSON.parse(response.body) else raise(API::Error.new(response.code, JSON.parse(response.body)["message"])) end end |
#destroy(uuid) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/arux_app/api/cart.rb', line 154 def destroy(uuid) path = "/api/#{self.generate_cart_path}/carts/#{uuid}" request = HTTPI::Request.new request.url = "#{api_uri}#{path}" request.headers = self.generate_headers response = HTTPI.delete(request) if !response.error? JSON.parse(response.body) else raise(API::Error.new(response.code, JSON.parse(response.body)["message"])) end end |
#get(uuid = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/arux_app/api/cart.rb', line 30 def get(uuid = nil) if uuid path = %(/api/#{AruxApp::API.uri_escape(uuid)}) else path = %(/api/#{self.generate_cart_path}) end request = HTTPI::Request.new request.url = "#{api_uri}#{path}" request.headers = self.generate_headers response = HTTPI.get(request) if !response.error? JSON.parse(response.body) else raise(API::Error.new(response.code, JSON.parse(response.body)["message"])) end end |
#get_item(item_identifier) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/arux_app/api/cart.rb', line 82 def get_item(item_identifier) path = %(/api/#{self.generate_cart_path}/items/#{item_identifier}) request = HTTPI::Request.new request.url = "#{api_uri}#{path}" request.headers = self.generate_headers response = HTTPI.get(request) if !response.error? JSON.parse(response.body) else raise(API::Error.new(response.code, JSON.parse(response.body)["message"])) end end |
#get_items ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/arux_app/api/cart.rb', line 66 def get_items path = %(/api/#{self.generate_cart_path}/items) request = HTTPI::Request.new request.url = "#{api_uri}#{path}" request.headers = self.generate_headers response = HTTPI.get(request) if !response.error? JSON.parse(response.body) else raise(API::Error.new(response.code, JSON.parse(response.body)["message"])) end end |
#get_status ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/arux_app/api/cart.rb', line 50 def get_status path = %(/api/#{self.generate_cart_path}/status) request = HTTPI::Request.new request.url = "#{api_uri}#{path}" request.headers = self.generate_headers response = HTTPI.get(request) if !response.error? JSON.parse(response.body) else raise(API::Error.new(response.code, JSON.parse(response.body)["message"])) end end |
#public_uri ⇒ Object
18 19 20 |
# File 'lib/arux_app/api/cart.rb', line 18 def public_uri self.class.public_uri end |
#update_item(item_identifier, params) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/arux_app/api/cart.rb', line 118 def update_item(item_identifier, params) path = %(/api/#{self.generate_cart_path}/items/#{AruxApp::API.uri_escape(item_identifier)}) request = HTTPI::Request.new request.url = "#{api_uri}#{path}" if params.keys.first.to_s != 'item' params = {:item => params} end request.body = params.to_json request.headers = self.generate_headers response = HTTPI.put(request) if !response.error? JSON.parse(response.body) else raise(API::Error.new(response.code, JSON.parse(response.body)["message"])) end end |