Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #111 from Shopify/add_customer_search

Add convenience method Customer#search
  • Loading branch information...
commit ef104d7fc794f3706dcfe7344d5c942855b74354 2 parents 152cc42 + 9f85324
@phoet phoet authored
View
1  CHANGELOG
@@ -3,6 +3,7 @@
* in Session::request_token params is no longer optional, you must pass all the params and the method will now extract the code
* Add access to FulfillmentService endpoint
* Fix JSON errors handling (#103)
+* Add convenience method Customer#search (#45)
== Version 3.1.8
View
5 lib/shopify_api/resources/customer.rb
@@ -3,8 +3,11 @@ class Customer < Base
include Metafields
def orders
- Order.find(:all, :params => {:customer_id => self.id})
+ Order.find(:all, params: {customer_id: self.id})
end
+ def self.search(params)
+ find(:all, from: :search, params: params)
+ end
end
end
View
10 test/customer_test.rb
@@ -0,0 +1,10 @@
+require 'test_helper'
+
+class CustomerTest < Test::Unit::TestCase
+ def test_search
+ fake "customers/search.json?query=Bob+country%3AUnited+States", extension: false, body: load_fixture('customers_search')
+
+ results = ShopifyAPI::Customer.search(query: 'Bob country:United States')
+ assert_equal 'Bob', results.first.first_name
+ end
+end
View
60 test/fixtures/customers_search.json
@@ -0,0 +1,60 @@
+{
+ "customers": [
+ {
+ "accepts_marketing": false,
+ "created_at": "2014-01-20T17:25:18-05:00",
+ "email": "bob.norman@hostmail.com",
+ "first_name": "Bob",
+ "id": 207119551,
+ "last_name": "Norman",
+ "last_order_id": null,
+ "multipass_identifier": null,
+ "note": null,
+ "orders_count": 0,
+ "state": "disabled",
+ "total_spent": "0.00",
+ "updated_at": "2014-01-20T17:25:18-05:00",
+ "verified_email": true,
+ "tags": "",
+ "last_order_name": null,
+ "default_address": {
+ "address1": "Chestnut Street 92",
+ "address2": "",
+ "city": "Louisville",
+ "company": null,
+ "country": "United States",
+ "first_name": null,
+ "id": 207119551,
+ "last_name": null,
+ "phone": "555-625-1199",
+ "province": "Kentucky",
+ "zip": "40202",
+ "name": null,
+ "province_code": "KY",
+ "country_code": "US",
+ "country_name": "United States",
+ "default": true
+ },
+ "addresses": [
+ {
+ "address1": "Chestnut Street 92",
+ "address2": "",
+ "city": "Louisville",
+ "company": null,
+ "country": "United States",
+ "first_name": null,
+ "id": 207119551,
+ "last_name": null,
+ "phone": "555-625-1199",
+ "province": "Kentucky",
+ "zip": "40202",
+ "name": null,
+ "province_code": "KY",
+ "country_code": "US",
+ "country_name": "United States",
+ "default": true
+ }
+ ]
+ }
+ ]
+}
Please sign in to comment.
Something went wrong with that request. Please try again.