Class: Kinja::Client

Inherits:
Object
  • Object
show all
Includes:
Analytics, 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

#all_in_tag, #get_posts_in_tag, #get_posts_in_tag_for_site, #get_tag_feed_for_site, #tag

Methods included from Analytics

#get_counts

Methods included from Author

#get_all_author_posts, #get_author, #get_author_id, #get_author_posts, #get_default_blog_id

Methods included from Blog

#get_blog_id, #get_feed, #get_latest_by_id, #get_latest_by_name, #get_members, #get_posts_in_month

Methods included from Post

#create_post, #get_post, #update_post

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
24
# File 'lib/kinja/client.rb', line 19

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.



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

def user
  @user
end

Instance Method Details

#get_api_token(response) ⇒ Object



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

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

#loginObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kinja/client.rb', line 26

def 
  response = HTTParty.post("#{API_ROOT}#{LOGIN_PATH}",
    body: {
      screenName: URI.encode(@username),
      token: @pass
    }.to_json,
    headers: { 'Content-Type' => 'application/json' }
  )
  @user = response["data"]
  response
end

#session_token(response) ⇒ Object



44
45
46
47
# File 'lib/kinja/client.rb', line 44

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