Class: Movescount::Member

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serialization, HTTParty
Defined in:
lib/movescount/member.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Member

Returns a new instance of Member.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/movescount/member.rb', line 11

def initialize(options={})
  raise ArgumentError, 'An email is required as an option' unless options[:email]
  raise ArgumentError, 'A userkey is required as an option' unless options[:userkey]
  self.class.base_uri Movescount.configuration.api_uri
  @options = {
    query: {
      appKey: Movescount.configuration.app_key,
      userKey: options.delete(:userkey),
      email: options.delete(:email)
    }
  }.merge options
end

Instance Attribute Details

#optionsObject (readonly)

debug_output $stderr



9
10
11
# File 'lib/movescount/member.rb', line 9

def options
  @options
end

Instance Method Details

#move_by_id(id) ⇒ Object

Get a move by move_id



48
49
50
# File 'lib/movescount/member.rb', line 48

def move_by_id(id)
  Move.new self, self.class.get("/moves/#{id}", @options)
end

#moves(options = {}, force = false) ⇒ Object

Returns the user’s moves Options include: startDate, endDate and maxcount Force argument forces reload of data from api



38
39
40
41
42
43
44
45
# File 'lib/movescount/member.rb', line 38

def moves(options = {}, force = false)
  # Return moves if present and not forcing reload
  return @moves if @moves && !force
  # Get moves from the api and create move objects
  @moves = get_moves(options).map do |move|
    Move.new self, move
  end
end

#profile(force = false) ⇒ Object

Returns the entire user profile Force argument forces reload of data from api



26
27
28
# File 'lib/movescount/member.rb', line 26

def profile(force = false)
  force ? @profile = get_profile : @profile ||= get_profile
end

#usernameObject

Returns the user’s movescount username



31
32
33
# File 'lib/movescount/member.rb', line 31

def username
  profile['Username']
end