Class: Viner::Client

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/viner/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#call, #connection

Constructor Details

#initializeClient

Returns a new instance of Client.



7
8
9
10
# File 'lib/viner/client.rb', line 7

def initialize
  @user_id = nil
  @key     = nil
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/viner/client.rb', line 5

def key
  @key
end

#user_idObject

Returns the value of attribute user_id.



5
6
7
# File 'lib/viner/client.rb', line 5

def user_id
  @user_id
end

Instance Method Details

#login(username, password) ⇒ Object

Login



13
14
15
16
17
18
19
# File 'lib/viner/client.rb', line 13

def (username, password)
  # POST https://api.vineapp.com/users/authenticate
  result = post('users/authenticate', {}, { username: username, password: password })
  self.user_id = result['data']['userId']
  self.key     = result['data']['key']
  result
end

#logoutObject

Logout



22
23
24
25
# File 'lib/viner/client.rb', line 22

def logout
  # DELETE https://api.vineapp.com/users/authenticate
  delete('users/authenticate', {}, {})
end

#notificationsObject

Get Notifications



68
69
70
71
# File 'lib/viner/client.rb', line 68

def notifications
  # GET https://api.vineapp.com/users/<userid>/pendingNotificationsCount
  get("users/#{@user_id}/pendingNotificationsCount", {}, {})
end

Get Popular



28
29
30
31
# File 'lib/viner/client.rb', line 28

def popular
  # GET https://api.vineapp.com/timelines/popular
  get('timelines/popular', {}, {})
end

#posts(post) ⇒ Object

Get Single Post



62
63
64
65
# File 'lib/viner/client.rb', line 62

def posts(post)
  # GET https://api.vineapp.com/timelines/posts/<postid>
  get("timelines/posts/#{post}", {}, {})
end

#profile(user = nil) ⇒ Object

Get User Data



45
46
47
48
49
50
51
52
53
# File 'lib/viner/client.rb', line 45

def profile(user = nil)
  if user
    # GET https://api.vineapp.com/users/profiles/<userid>
    get("users/profiles/#{user}", {}, {})
  else
    # GET https://api.vineapp.com/users/me
    get("users/me", {}, {})
  end
end

#search(username) ⇒ Object



33
34
35
36
# File 'lib/viner/client.rb', line 33

def search(username)
  # GET https://api.vineapp.com/users/search/<username>
  get("users/search/#{username}", {}, {}).data.records
end

#tag(tag) ⇒ Object

Get Tag



39
40
41
42
# File 'lib/viner/client.rb', line 39

def tag(tag)
  # GET https://api.vineapp.com/timelines/tags/<tag>
  get("timelines/tags/#{tag}", {}, {})
end

#timeline(user_id) ⇒ Object



55
56
57
58
59
# File 'lib/viner/client.rb', line 55

def timeline(user_id)
  # GET https://api.vineapp.com/timelines/users/<userid>
  result = get("timelines/users/#{user_id}", {}, {})
  return result.data.records if result.success
end