Class: Traktr::Activity

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/traktr/activity.rb,
lib/traktr/activity/user.rb

Defined Under Namespace

Classes: User

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Activity

Returns a new instance of Activity.



6
7
8
# File 'lib/traktr/activity.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#community(types = :all, actions = :all, start_ts = 0, end_ts = Time.now.to_i) ⇒ Object

activity GET methods

Raises:

  • (ResponseError)


13
14
15
16
17
18
# File 'lib/traktr/activity.rb', line 13

def community(types = :all, actions = :all, start_ts = 0, end_ts = Time.now.to_i)
  response = self.class.get('/' + File.join('community.json', @client.api_key, types.to_s, actions.to_s, start_ts.to_s, end_ts.to_s))
  raise ResponseError.new(response) if response.code != 200

  Mash.new(response.parsed_response)
end

#episodes(title, season, episode, actions = :all, start_ts = 0, end_ts = Time.now.to_i) ⇒ Object

Raises:

  • (ResponseError)


20
21
22
23
24
25
# File 'lib/traktr/activity.rb', line 20

def episodes(title, season, episode, actions = :all, start_ts = 0, end_ts = Time.now.to_i)
  response = self.class.get('/' + File.join('episodes.json', @client.api_key, title, season.to_s, episode.to_s, actions.to_s, start_ts.to_s, end_ts.to_s))
  raise ResponseError.new(response) if response.code != 200

  Mash.new(response.parsed_response)
end

#friends(types = :all, actions = :all, start_ts = 0, end_ts = Time.now.to_i) ⇒ Object

activity POST methods

Raises:

  • (ResponseError)


62
63
64
65
66
67
68
# File 'lib/traktr/activity.rb', line 62

def friends(types = :all, actions = :all, start_ts = 0, end_ts = Time.now.to_i)
  data = { username: @client.username, password: @client.password }
  response = self.class.post('/' + File.join('friends.json', @client.api_key, types.to_s, actions.to_s, start_ts.to_s, end_ts.to_s), body: data.to_json, headers: { 'Content-Type' => 'application/json'})
  raise ResponseError.new(response) if response.code != 200

  Mash.new(response.parsed_response)
end

#movies(title, actions = :all, start_ts = 0, end_ts = Time.now.to_i) ⇒ Object

Raises:

  • (ResponseError)


27
28
29
30
31
32
# File 'lib/traktr/activity.rb', line 27

def movies(title, actions = :all, start_ts = 0, end_ts = Time.now.to_i)
  response = self.class.get('/' + File.join('movies.json', @client.api_key, title, actions.to_s, start_ts.to_s, end_ts.to_s))
  raise ResponseError.new(response) if response.code != 200

  Mash.new(response.parsed_response)
end

#seasons(title, season, actions = :all, start_ts = 0, end_ts = Time.now.to_i) ⇒ Object

Raises:

  • (ResponseError)


34
35
36
37
38
39
# File 'lib/traktr/activity.rb', line 34

def seasons(title, season, actions = :all, start_ts = 0, end_ts = Time.now.to_i)
  response = self.class.get('/' + File.join('seasons.json', @client.api_key, title, season.to_s, actions.to_s, start_ts.to_s, end_ts.to_s))
  raise ResponseError.new(response) if response.code != 200

  Mash.new(response.parsed_response)
end

#shows(title, actions = :all, start_ts = 0, end_ts = Time.now.to_i) ⇒ Object

Raises:

  • (ResponseError)


41
42
43
44
45
46
# File 'lib/traktr/activity.rb', line 41

def shows(title, actions = :all, start_ts = 0, end_ts = Time.now.to_i)
  response = self.class.get('/' + File.join('shows.json', @client.api_key, title, actions.to_s, start_ts.to_s, end_ts.to_s))
  raise ResponseError.new(response) if response.code != 200

  Mash.new(response.parsed_response)
end

#user(username = nil, types = :all, actions = :all, start_ts = 0, end_ts = Time.now.to_i) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/traktr/activity.rb', line 48

def user(username = nil, types = :all, actions = :all, start_ts = 0, end_ts = Time.now.to_i)
  if username
    response = self.class.get('/' + File.join('user.json', @client.api_key, username, types.to_s, actions.to_s, start_ts.to_s, end_ts.to_s))
    raise ResponseError.new(response) if response.code != 200

    Mash.new(response.parsed_response)
  else
    @user ||= Traktr::Activity::User.new(@client)
  end
end