Class: Redvine

Inherits:
Object
  • Object
show all
Defined in:
lib/redvine.rb,
lib/redvine/version.rb

Defined Under Namespace

Classes: AuthenticationRequiredError, ConnectionError, Error

Constant Summary collapse

VERSION =
"0.2"
@@baseUrl =
'https://api.vineapp.com/'
@@deviceToken =
SecureRandom.hex 32
@@userAgent =
'iphone/1.3.1 (iPhone; iOS 6.1.3; Scale/2.00) (Redvine)'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#user_idObject (readonly)

Returns the value of attribute user_id.



22
23
24
# File 'lib/redvine.rb', line 22

def user_id
  @user_id
end

#usernameObject (readonly)

Returns the value of attribute username.



22
23
24
# File 'lib/redvine.rb', line 22

def username
  @username
end

#vine_keyObject (readonly)

Returns the value of attribute vine_key.



22
23
24
# File 'lib/redvine.rb', line 22

def vine_key
  @vine_key
end

Instance Method Details

#connect(opts = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/redvine.rb', line 28

def connect(opts={})
  validate_connect_args(opts)
  query = {username: opts[:email], password: opts[:password], deviceToken: @@deviceToken}
  headers = {'User-Agent' => @@userAgent}
  response = HTTParty.post(@@baseUrl + 'users/authenticate', {body: query, headers: headers})
  if opts[:skip_exception] || response['success']
    @vine_key = response.parsed_response['data']['key']
    @username = response.parsed_response['data']['username']
    @user_id = response.parsed_response['data']['userId']
  else
    raise Redvine::ConnectionError.new(response['code'].to_i), response['error']
  end
end

#followers(uid, opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


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

def followers(uid,opts={})
  raise(ArgumentError, 'You must specify a user id') if !uid
  get_request_data("users/#{uid}/followers", opts)
end

#following(uid, opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


63
64
65
66
# File 'lib/redvine.rb', line 63

def following(uid,opts={})
  raise(ArgumentError, 'You must specify a user id') if !uid
  get_request_data("users/#{uid}/following", opts)
end

#likes(opts = {}) ⇒ Object



59
60
61
# File 'lib/redvine.rb', line 59

def likes(opts={})
  user_likes(@user_id.to_s, opts)
end


47
48
49
# File 'lib/redvine.rb', line 47

def popular(opts={})
  get_request_data('timelines/popular', opts)
end


51
52
53
# File 'lib/redvine.rb', line 51

def promoted(opts={})
  get_request_data('timelines/promoted', opts)
end

#search(tag, opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


42
43
44
45
# File 'lib/redvine.rb', line 42

def search(tag, opts={})
  raise(ArgumentError, 'You must specify a tag') if !tag
  get_request_data('timelines/tags/' + tag, opts)
end

#single_post(pid) ⇒ Object

Raises:

  • (ArgumentError)


88
89
90
91
92
# File 'lib/redvine.rb', line 88

def single_post(pid)
  raise(ArgumentError, 'You must specify a post id') if !pid
  response = get_request_data('/timelines/posts/' + pid)
  return response.kind_of?(Array) ? response.first : response
end

#timeline(opts = {}) ⇒ Object



55
56
57
# File 'lib/redvine.rb', line 55

def timeline(opts={})
  get_request_data('timelines/graph', opts)
end

#user_likes(uid, opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


83
84
85
86
# File 'lib/redvine.rb', line 83

def user_likes(uid, opts={})
  raise(ArgumentError, 'You must specify a user id') if !uid
  get_request_data('timelines/users/' + uid + '/likes', opts)
end

#user_profile(uid) ⇒ Object

Raises:

  • (ArgumentError)


73
74
75
76
# File 'lib/redvine.rb', line 73

def (uid)
  raise(ArgumentError, 'You must specify a user id') if !uid
  get_request_data('users/profiles/' + uid, {}, false)
end

#user_timeline(uid, opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


78
79
80
81
# File 'lib/redvine.rb', line 78

def user_timeline(uid, opts={})
  raise(ArgumentError, 'You must specify a user id') if !uid
  get_request_data('timelines/users/' + uid, opts)
end