class Pergola::Client

Attributes

session[RW]
user_id[RW]

Public Class Methods

new(options={}) click to toggle source

Initialize the Pergola client

E.G. client = Pergola::Client.new(:username => “email”, :password => “sekret”)

# File lib/pergola/client.rb, line 12
def initialize(options={})
  if options[:token]
    @session = options[:token]
    @user_id = options[:token].match(/(\d*(?=-))/)[0]
  elsif options[:username] && options[:password]
    response = self.class.post('/users/authenticate', body: {username: options[:username], password: options[:password] })
    @user_id = response["data"]["userId"]
    @session = response["data"]["key"]
  end

  Pergola.session = @session
  Pergola.user_id = @user_id

  @headers = {:headers => {"vine-session-id" => @session}}
end

Public Instance Methods

get_notifications() click to toggle source

client.get_notifications #=> get pending notifications

# File lib/pergola/client.rb, line 61
def get_notifications
  path = "/users/#{@user_id}/pendingNotificationsCount"
  self.request(path)
end
logout() click to toggle source

client.logout #=> destroys the client session

# File lib/pergola/client.rb, line 29
def logout
  path = "/users/authenticate"
  self.request(path, :delete)
end
me() click to toggle source
# File lib/pergola/client.rb, line 42
def me
  path = "/users/me"
  self.request(path)
end
profile(user_id = @user_id) click to toggle source

client.profile #=> Your Profile client.me #=> Your Profile client.profile(‘user_id’) #=> some user’s profile

# File lib/pergola/client.rb, line 37
def profile(user_id = @user_id)
  path = "/users/profiles/#{user_id}"
  self.request(path)
end
request(path, method=:get) click to toggle source
# File lib/pergola/client.rb, line 72
def request(path, method=:get)
  request = self.class.send(method, path, @headers)

  if request["code"] != ""
    config = Pergola.configuration
    puts "YOUR SESSION IS NO LONGER VALID"
    puts "REINITIALIZING YOUR SESSION BASED ON CONFIGURATION.RB"

    new_client = self.class.new(username: config.username, password: config.password)
    @headers = {:headers => {"vine-session-id" => new_client.session}}

    puts "RETRYING THE API CALL"
    request = self.class.send(method, path, @headers)
  end
  request
end
timeline(user_id = @user_id) click to toggle source

client.timeline #=> your timeline client.timeline(‘user_id’) #=> friend’s timeline

# File lib/pergola/client.rb, line 49
def timeline(user_id = @user_id)
  path = "/timelines/users/#{user_id}"
  self.request(path)
end
with_tag(tag) click to toggle source

client.tag(“brooklyn”) #=> find vines with similar tags

# File lib/pergola/client.rb, line 55
def with_tag(tag)
  path = "/timelines/tags/#{tag}"
  self.request(path)
end