Class: Yipit::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yipit.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Client

Initialize the client. TODO: Document.



11
12
13
14
15
16
17
18
19
20
# File 'lib/yipit.rb', line 11

def initialize(*args)
  options = args.extract_options!
  @api_key = args[0]
  @conn = Faraday.new(:url => "http://api.yipit.com") do |builder|
    builder.adapter Faraday.default_adapter
    builder.adapter  :logger if options[:debug] == true
    builder.use Faraday::Response::ParseJson
    builder.use Faraday::Response::Mashify
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



81
82
83
84
85
86
# File 'lib/yipit.rb', line 81

def method_missing(sym, *args, &block)
  options = args.extract_options!.merge(:key => api_key)
  response = conn.get("/v1/#{sym.to_s}/#{args[0]}") { |req| req.params = options  }
  ret = response.body.response.send sym
  args[0].nil? ? ret : ret.first if ret
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/yipit.rb', line 7

def api_key
  @api_key
end

#connObject (readonly)

Returns the value of attribute conn.



7
8
9
# File 'lib/yipit.rb', line 7

def conn
  @conn
end

Instance Method Details

#businesses(*args) ⇒ Object



77
78
79
# File 'lib/yipit.rb', line 77

def businesses(*args)
  super
end

#deals(options = {}) ⇒ Array #deals(deal_id) ⇒ Hashie::Mash

Overloads:

  • #deals(options = {}) ⇒ Array

    Search for Deals

    Examples:

    Search deals by latitude and longitude

    client.deals(:lat => "-37.74", :lon => "-76.00")

    Search deals within a 2 miles radius of latitude and longitude

    client.deals(:lat => "-37.74", :lon => "-76.00", :radius => 2)

    Search deals from Groupon

    client.deals(:source => "Groupon")

    Search deals based on phone number

    client.deals(:phone => "7185551212")

    Search deals based on tags

    client.deals(:tag => "restaurants,spa")

    Search deals based on paid status. (Defaults to false)

    client.deals(:paid => true)

    Parameters:

    • options (Hash) (defaults to: {})

      A customizable set of options

    Options Hash (options):

    • :lat (String)

      Latitude of point to to sort deals by proximity to. Use with lon. Uses radius.

    • :lon (String)

      Longitude of point to to sort deals by proximity to. Use with lat. Uses radius.

    • :radius (Fixnum)

      Maximum distance of radius in miles to deal location from center point. Defaults to 10. Requires lat and lon

    • :divisions (String)

      One or more division slugs (comma separated). See Divisions API for more details.

    • :source (String)

      One or more source slugs (comma separated). See Sources API for more details.

    • :phone (String)

      Deals available at a business matching one of the phone numbers. See Businesses API for more details.

    • :tag (String)

      One or more tag slugs (comma separated). See Tags API for more details. Note: Specifying multiple tags returns deals matching any one of the tags, NOT all of them

    • :paid (Boolean)

      Shows deals filtered on paid status. Defaults to false. Set to true if you would like to see all deals.

    Returns:

    • (Array)

      An array of Hashie::Mash objects representing Yipit deals

  • #deals(deal_id) ⇒ Hashie::Mash

    Get deal details

    Parameters:

    • deal_id (Fixnum)

      A Deal Id

    Returns:

    • (Hashie::Mash)

      A Hashie::Mash object representing a Yipit deal



50
51
52
# File 'lib/yipit.rb', line 50

def deals(*args)
  super
end

#divisions(*args) ⇒ Object



74
75
76
# File 'lib/yipit.rb', line 74

def divisions(*args)
  super
end

#sources(options = {}) ⇒ Object #sources(source_id) ⇒ Hashie::Mash

Overloads:

  • #sources(options = {}) ⇒ Object

    Search for sources

    Parameters:

    • options (Hash) (defaults to: {})

      A customizable set of options

    Options Hash (options):

    • :division (String)

      One or more division slugs. See Divisions API for more details. Note: Specifying multiple divisions returns sources that exist in either of the divisions, NOT all of them.

    • :paid (String)

      When paid is true, only paid sources are returned. Defaults to false.

  • #sources(source_id) ⇒ Hashie::Mash

    Get source details

    Parameters:

    • slug (String)

      A source slug

    Returns:

    • (Hashie::Mash)

      A Hashie::Mash object representing a Yipit Deal Source



63
64
65
# File 'lib/yipit.rb', line 63

def sources(*args)
  super
end

#tags(options = {}) ⇒ Array

This method returns a list of all tags. There are no parameters specific to tags.

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options

Returns:

  • (Array)

    An array of Hashie::Mash objects representing Yipit tags.



71
72
73
# File 'lib/yipit.rb', line 71

def tags(*args)
  super
end