Module: AddThis::Requests

Included in:
Client
Defined in:
lib/add_this/requests.rb

Class Method Summary collapse

Class Method Details

.requests(*args) ⇒ Object

requests method

Defines the get request for all the methods by splitting the method name and the underscore to keep things dry as well allows your to pass a hash for all the query params

Parameters:

  • args (Hash)

    a customizable set of options

Options Hash (*args):

  • all (Array)

    of the symbolized method names



16
17
18
19
20
21
22
23
24
25
# File 'lib/add_this/requests.rb', line 16

def self.requests(*args)
  args.each do |arg|
    define_method arg do |*options|
      metric, dimension = arg.to_s.split("_")
      connection.get do |req|
        req.url("/analytics/1.0/pub/#{metric}/#{dimension}.json", options[0] || {})
      end.body
    end
  end
end