Permalink
Browse files

Merge pull request #111 from Shopify/add_customer_search

Add convenience method Customer#search
  • Loading branch information...
2 parents 152cc42 + 9f85324 commit ef104d7fc794f3706dcfe7344d5c942855b74354 @phoet phoet committed Jan 22, 2014
Showing with 75 additions and 1 deletion.
  1. +1 −0 CHANGELOG
  2. +4 −1 lib/shopify_api/resources/customer.rb
  3. +10 −0 test/customer_test.rb
  4. +60 −0 test/fixtures/customers_search.json
View
@@ -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
@@ -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
@@ -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
@@ -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
+ }
+ ]
+ }
+ ]
+}

0 comments on commit ef104d7

Please sign in to comment.