Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add convenience method Customer#search #111

Merged
merged 2 commits into from

3 participants

@phoet

Closes #45. Unfortunately the Repo of the original pull-request does no longer exist, so the commits are actually lost and I had to apply them myself, so @edelbalso is not going to be the author of this.

@maartenvg @costford :eyes:

@phoet phoet Add convenience method Customer#search
Closes #45. Unfortunately the Repo of the original pull-request does no longer exist, so the commits are actually lost and I had to apply them myself, so @edelbalso is not going to be the author of this.
f4101b4
lib/shopify_api/resources/customer.rb
((6 lines not shown))
end
+ def self.search(params)
+ find(:all, from: '/admin/customers/search.json', params: params)
@maartenvg Collaborator

Shouldn't the prefixing, etc, take care of :from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@maartenvg
Collaborator

I like this version! :sheep:

@costford
Collaborator

Yea, LGTM :+1:

@phoet phoet merged commit ef104d7 into master
@maartenvg maartenvg deleted the add_customer_search branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 22, 2014
  1. @phoet

    Add convenience method Customer#search

    phoet authored
    Closes #45. Unfortunately the Repo of the original pull-request does no longer exist, so the commits are actually lost and I had to apply them myself, so @edelbalso is not going to be the author of this.
  2. @phoet
This page is out of date. Refresh to see the latest.
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
+ }
+ ]
+ }
+ ]
+}
Something went wrong with that request. Please try again.