Module: Epages::REST::Utils
- Included in:
- Carts, Categories, Customers, Newsletters, Orders, Products, Sales, TaxClasses, Webhooks
- Defined in:
- lib/epages/rest/utils.rb
Instance Method Summary collapse
- #epages_id(object) ⇒ Object
- #format_date(date) ⇒ Object
- #format_dates_options(options) ⇒ Object
- #parse_legal_info(data) ⇒ Object
- #parse_links(data) ⇒ Object
- #parse_price_info(data) ⇒ Object
- #parse_product_lowest_price(data) ⇒ Object
- #parse_product_variations(data) ⇒ Object
- #parse_suggestions_to_products(data) ⇒ Object
- #parse_variation_object(data) ⇒ Object
- #parse_variations(data) ⇒ Object
- #perform_delete_request(path, options = {}) ⇒ Object
- #perform_delete_with_object(path, options, klass) ⇒ Object
- #perform_get_request(path, options = {}) ⇒ Object
- #perform_get_with_key_and_objects(path, options, key, klass) ⇒ Object
- #perform_get_with_object(path, options, klass) ⇒ Object
- #perform_get_with_objects(path, options, klass) ⇒ Object
- #perform_multipart_post_with_objects(path, image, klass) ⇒ Object
- #perform_patch_with_object(path, options, klass) ⇒ Object
- #perform_post_request(path, options = {}) ⇒ Object
- #perform_post_with_key_and_objects(path, options, key, klass) ⇒ Object
- #perform_post_with_object(path, options, klass) ⇒ Object
- #perform_post_with_objects(path, options, klass) ⇒ Object
- #perform_put_request(path, options = {}) ⇒ Object
- #perform_put_with_object(path, options, klass) ⇒ Object
- #perform_request(request_method, path, options = {}) ⇒ Object
- #perform_request_with_key_and_objects(request_method, path, options, key, klass) ⇒ Object
- #perform_request_with_object(request_method, path, options, klass) ⇒ Object
- #perform_request_with_objects(request_method, path, options, klass) ⇒ Object
- #process_thread(key, value, index = nil) ⇒ Object
Instance Method Details
#epages_id(object) ⇒ Object
137 138 139 140 141 |
# File 'lib/epages/rest/utils.rb', line 137 def epages_id(object) return object if object.class == String return if object.class.name.deconstantize != 'Epages' object.send(:id) end |
#format_date(date) ⇒ Object
197 198 199 |
# File 'lib/epages/rest/utils.rb', line 197 def format_date(date) (date.is_a?(Date) ? date : DateTime.parse(date)).strftime end |
#format_dates_options(options) ⇒ Object
201 202 203 204 205 |
# File 'lib/epages/rest/utils.rb', line 201 def () [:created_before] = format_date([:created_before]) if [:created_before] [:created_after] = format_date([:created_after]) if [:created_after] end |
#parse_legal_info(data) ⇒ Object
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/epages/rest/utils.rb', line 157 def parse_legal_info(data) { contact_info: Epages::ContentPageSummary.new(data[:contactInformation].nil? ? {'':''} : data[:contactInformation]), privacy_policy: Epages::ContentPageSummary.new(data[:privacyPolicy].nil? ? {'':''} : data[:privacyPolicy]), terms_and_conditions: Epages::ContentPageSummary.new(data[:termsAndConditions].nil? ? {'':''} : data[:termsAndConditions]), rights_of_withdrawal: Epages::ContentPageSummary.new(data[:rightsOfWithdrawal].nil? ? {'':''} : data[:rightsOfWithdrawal]), shipping_info: Epages::ContentPageSummary.new(data[:shippingInformation].nil? ? {'':''} : data[:shippingInformation]), links: parse_links(data[:links]), } end |
#parse_links(data) ⇒ Object
180 181 182 |
# File 'lib/epages/rest/utils.rb', line 180 def parse_links(data) data.collect { |link| Epages::Link.new(link) } end |
#parse_price_info(data) ⇒ Object
176 177 178 |
# File 'lib/epages/rest/utils.rb', line 176 def parse_price_info(data) Epages::PriceInfo.new(data) end |
#parse_product_lowest_price(data) ⇒ Object
150 151 152 153 154 155 |
# File 'lib/epages/rest/utils.rb', line 150 def parse_product_lowest_price(data) { price_info: parse_price_info(data[:priceInfo]), links: parse_links(data[:links]), } end |
#parse_product_variations(data) ⇒ Object
143 144 145 146 147 148 |
# File 'lib/epages/rest/utils.rb', line 143 def parse_product_variations(data) { variation_attributes: parse_variations(data), items: parse_variation_object(data), } end |
#parse_suggestions_to_products(data) ⇒ Object
184 185 186 187 |
# File 'lib/epages/rest/utils.rb', line 184 def parse_suggestions_to_products(data) ids = data[:products].collect { |p| p[:link][:href].split('/').last } parallel_calls(product: ids)[:product] end |
#parse_variation_object(data) ⇒ Object
172 173 174 |
# File 'lib/epages/rest/utils.rb', line 172 def parse_variation_object(data) data[:items].collect { |el| Epages::Variation.new(el) } end |
#parse_variations(data) ⇒ Object
168 169 170 |
# File 'lib/epages/rest/utils.rb', line 168 def parse_variations(data) data[:variationAttributes].collect { |el| Epages::VariationAttribute.new(el) } end |
#perform_delete_request(path, options = {}) ⇒ Object
133 134 135 |
# File 'lib/epages/rest/utils.rb', line 133 def perform_delete_request(path, = {}) perform_request(:delete, path, ) end |
#perform_delete_with_object(path, options, klass) ⇒ Object
42 43 44 |
# File 'lib/epages/rest/utils.rb', line 42 def perform_delete_with_object(path, , klass) perform_request_with_object(:delete, path, , klass) end |
#perform_get_request(path, options = {}) ⇒ Object
115 116 117 |
# File 'lib/epages/rest/utils.rb', line 115 def perform_get_request(path, = {}) perform_request(:get, path, ) end |
#perform_get_with_key_and_objects(path, options, key, klass) ⇒ Object
91 92 93 |
# File 'lib/epages/rest/utils.rb', line 91 def perform_get_with_key_and_objects(path, , key, klass) perform_request_with_key_and_objects(:get, path, , key, klass) end |
#perform_get_with_object(path, options, klass) ⇒ Object
14 15 16 |
# File 'lib/epages/rest/utils.rb', line 14 def perform_get_with_object(path, , klass) perform_request_with_object(:get, path, , klass) end |
#perform_get_with_objects(path, options, klass) ⇒ Object
58 59 60 |
# File 'lib/epages/rest/utils.rb', line 58 def perform_get_with_objects(path, , klass) perform_request_with_objects(:get, path, , klass) end |
#perform_multipart_post_with_objects(path, image, klass) ⇒ Object
72 73 74 75 |
# File 'lib/epages/rest/utils.rb', line 72 def perform_multipart_post_with_objects(path, image, klass) response = perform_request(:multipart_post, path, file: image) response.key?('items') ? response[:items].collect { |data| klass.new(data) } : klass.new(response) end |
#perform_patch_with_object(path, options, klass) ⇒ Object
35 36 37 |
# File 'lib/epages/rest/utils.rb', line 35 def perform_patch_with_object(path, , klass) perform_request_with_object(:patch, path, , klass) end |
#perform_post_request(path, options = {}) ⇒ Object
121 122 123 |
# File 'lib/epages/rest/utils.rb', line 121 def perform_post_request(path, = {}) perform_request(:post, path, ) end |
#perform_post_with_key_and_objects(path, options, key, klass) ⇒ Object
99 100 101 |
# File 'lib/epages/rest/utils.rb', line 99 def perform_post_with_key_and_objects(path, , key, klass) perform_request_with_key_and_objects(:post, path, , key, klass) end |
#perform_post_with_object(path, options, klass) ⇒ Object
21 22 23 |
# File 'lib/epages/rest/utils.rb', line 21 def perform_post_with_object(path, , klass) perform_request_with_object(:post, path, , klass) end |
#perform_post_with_objects(path, options, klass) ⇒ Object
65 66 67 |
# File 'lib/epages/rest/utils.rb', line 65 def perform_post_with_objects(path, , klass) perform_request_with_objects(:post, path, , klass) end |
#perform_put_request(path, options = {}) ⇒ Object
127 128 129 |
# File 'lib/epages/rest/utils.rb', line 127 def perform_put_request(path, = {}) perform_request(:put, path, ) end |
#perform_put_with_object(path, options, klass) ⇒ Object
28 29 30 |
# File 'lib/epages/rest/utils.rb', line 28 def perform_put_with_object(path, , klass) perform_request_with_object(:put, path, , klass) end |
#perform_request(request_method, path, options = {}) ⇒ Object
7 8 9 |
# File 'lib/epages/rest/utils.rb', line 7 def perform_request(request_method, path, = {}) Epages::REST::Request.new(self, request_method, path, ).perform end |
#perform_request_with_key_and_objects(request_method, path, options, key, klass) ⇒ Object
107 108 109 110 111 |
# File 'lib/epages/rest/utils.rb', line 107 def perform_request_with_key_and_objects(request_method, path, , key, klass) perform_request(request_method, path, )[key].collect do |element| klass.new(element) end end |
#perform_request_with_object(request_method, path, options, klass) ⇒ Object
50 51 52 53 |
# File 'lib/epages/rest/utils.rb', line 50 def perform_request_with_object(request_method, path, , klass) response = perform_request(request_method, path, ) klass.new(response) end |
#perform_request_with_objects(request_method, path, options, klass) ⇒ Object
81 82 83 84 85 |
# File 'lib/epages/rest/utils.rb', line 81 def perform_request_with_objects(request_method, path, , klass) perform_request(request_method, path, ).collect do |element| klass.new(element) end end |
#process_thread(key, value, index = nil) ⇒ Object
189 190 191 192 193 194 195 |
# File 'lib/epages/rest/utils.rb', line 189 def process_thread(key, value, index = nil) Thread.new do Thread.current[:name] = key Thread.current[:index] = index if index Thread.current[:result] = send(key, value) end end |