Class: Kinja::Client

Inherits:
Object
  • Object
show all
Includes:
Author, Blog, Helper, Post, Tag
Defined in:
lib/kinja/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#get_post_id

Methods included from Tag

#get_posts_in_tag, #get_posts_in_tag_for_site, #get_tag_feed_for_site, #tag

Methods included from Author

#get_author, #get_default_blog_id

Methods included from Blog

#get_blog_id, #get_feed, #get_latest_by_id, #get_latest_by_name

Methods included from Post

#create_post, #get_post, #update_post

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
22
# File 'lib/kinja/client.rb', line 17

def initialize(opts={})
  if opts.has_key? :user and opts.has_key? :password
    @username = opts[:user]
    @pass = opts[:password]
  end
end

Instance Attribute Details

#userObject

Returns the value of attribute user.



10
11
12
# File 'lib/kinja/client.rb', line 10

def user
  @user
end

Instance Method Details

#get_api_token(response) ⇒ Object



30
31
32
33
34
# File 'lib/kinja/client.rb', line 30

def get_api_token(response)
  @api_token = HTTParty.get("#{API_ROOT}#{TOKEN_PATH}",
    cookies: {KinjaSession: session_token(response)}
              )['data']['token']
end

#loginObject



24
25
26
27
28
# File 'lib/kinja/client.rb', line 24

def 
  response = HTTParty.get "#{API_ROOT}#{LOGIN_PATH}?screenName=#{URI.encode @username}&token=#{URI.encode @pass}"
  @user = response["data"]
  response
end

#session_token(response) ⇒ Object



36
37
38
39
# File 'lib/kinja/client.rb', line 36

def session_token(response)
  re = /KinjaSession=([\w-]+);/
  response.headers["set-cookie"].match(re)[1]
end