class Moves::Client

Constants

ENDPOINT

Attributes

access_token[R]

Public Class Methods

new(access_token) click to toggle source
# File lib/moves.rb, line 11
def initialize(access_token)
  @access_token = access_token
end

Public Instance Methods

activity_list() click to toggle source
# File lib/moves.rb, line 35
def activity_list
  get "activities"
end
daily_activities(*args) click to toggle source
# File lib/moves.rb, line 23
def daily_activities(*args)
  get_range "user/activities/daily", *args
end
daily_places(*args) click to toggle source
# File lib/moves.rb, line 27
def daily_places(*args)
  get_range "user/places/daily", *args
end
daily_storyline(*args) click to toggle source
# File lib/moves.rb, line 31
def daily_storyline(*args)
  get_range "user/storyline/daily", *args
end
daily_summary(*args) click to toggle source
# File lib/moves.rb, line 19
def daily_summary(*args)
  get_range "user/summary/daily", *args
end
profile() click to toggle source
# File lib/moves.rb, line 15
def profile
  get "user/profile"
end

Protected Instance Methods

get(path, params = {}) click to toggle source
# File lib/moves.rb, line 41
def get(path, params = {})
  response = RestClient.get "#{ENDPOINT}#{path}", :params => {:access_token => @access_token}.merge(params)
  JSON.parse(response.body)
end
get_range(path, *args) click to toggle source
# File lib/moves.rb, line 46
def get_range(path, *args)
  format = "%Y-%m-%d"

  extra_path, params =
    if args[0].is_a?(Hash)
      ["", args[0]]
    elsif args[0].respond_to?(:strftime)
      ["/#{args[0].strftime(format)}", args[1]]
    elsif args[0].is_a?(Range)
      ["", {:from => args[0].first, to: args[0].last}]
    elsif args.compact.empty?
      ["", nil]
    else
      ["/#{args[0]}", args[1]]
    end
  params ||= {}

  # default to current day
  if extra_path.empty? and !(params[:to] or params[:from] or params[:pastDays])
    extra_path = "/#{Time.now.strftime(format)}"
  end

  if params[:to].respond_to?(:strftime)
    params[:to] = params[:to].strftime(format)
  end

  if params[:from].respond_to?(:strftime)
    params[:from] = params[:from].strftime(format)
  end

  if params[:updatedSince].respond_to?(:utc)
    params[:updatedSince] = params[:updatedSince].utc.strftime("%Y%m%dT%H%M%SZ")
  end

  get "#{path}#{extra_path}", params
end