kinja 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f18df055b7ad7d92f2b414d1903868399512353e
4
- data.tar.gz: 343563a612e32b7eb04893034cf7707dee70cfea
3
+ metadata.gz: 42e56c6157ae8376d8a7560a9675286dccc66d58
4
+ data.tar.gz: b1d9497cc43198a073754b9fe9b1e326b62969d0
5
5
  SHA512:
6
- metadata.gz: 855d6ebaa8934013978148236516267e895bb3d8a33b07cd525a261b3ca3d21d6c8cd8dd564408ef053b60bf23c8afc89808daaf22603ee4292358d0fba94b02
7
- data.tar.gz: 74d78747a4347107719357f94541b8f8011cf3c0b29c9ffab95e5cd3f1eec745a7d1258315a87a47f21baa3d010f913e1bf72aeb27ebaf35738dd66cbf8c9287
6
+ metadata.gz: 186b1d8b6482adf56e48799a2637cd39e8cf6ad3de8381a9f42ce6edf523d6a7f637c8fe4b934c9d282f18f82d3a8e17a9c3feaa5ec64bea311dd831c3579562
7
+ data.tar.gz: 1309abe2819c359fb39fd3fdebc52ce42cac52e9128b65df2b1c4e4e367a159ff172257f50d7244c7384a05b562324f1acb2f7d6905ffb246c9620493e56736b
@@ -0,0 +1,12 @@
1
+ module Kinja
2
+ module Author
3
+ def get_author(user)
4
+ HTTParty.get(author_path(user["id"]))["data"]
5
+ end
6
+
7
+ def get_default_blog_id(user)
8
+ get_author(user)[0]["defaultBlogId"]
9
+ end
10
+ end
11
+ end
12
+
data/lib/kinja/blog.rb ADDED
@@ -0,0 +1,32 @@
1
+ module Kinja
2
+ module Blog
3
+ def get_feed(name_or_id)
4
+ if name_or_id.is_a? String
5
+ feed = get_latest_by_name(name_or_id)
6
+ else
7
+ feed = get_latest_by_id(name_or_id)
8
+ end
9
+ if feed["meta"]["success"]
10
+ feed["data"]["items"]
11
+ else
12
+ feed
13
+ end
14
+ end
15
+
16
+ def get_latest_by_id(id)
17
+ HTTParty.get blog_latest_by_id_path(id)
18
+ end
19
+
20
+ def get_latest_by_name(name)
21
+ id = get_blog_id(name)
22
+ get_latest_by_id id
23
+ end
24
+
25
+ def get_blog_id(name)
26
+ profile = HTTParty.get(blog_profile_path(name))
27
+ profile["data"]["id"]
28
+ end
29
+
30
+ end
31
+ end
32
+
@@ -0,0 +1,41 @@
1
+ require "kinja/post"
2
+ require "kinja/blog"
3
+ require "kinja/author"
4
+ require "kinja/tag"
5
+ require "kinja/helpers"
6
+ require 'httparty'
7
+
8
+ module Kinja
9
+ class Client
10
+ attr_accessor :user
11
+ include Kinja::Post
12
+ include Kinja::Blog
13
+ include Kinja::Author
14
+ include Kinja::Tag
15
+ include Kinja::Helper
16
+
17
+ def initialize(opts={})
18
+ if opts.has_key? :user and opts.has_key? :password
19
+ @username = opts[:user]
20
+ @pass = opts[:password]
21
+ end
22
+ end
23
+
24
+ def login
25
+ response = HTTParty.get "#{API_ROOT}#{LOGIN_PATH}?screenName=#{@username}&token=#{@pass}"
26
+ @user = response["data"]
27
+ response
28
+ end
29
+
30
+ def get_api_token(response)
31
+ @api_token = HTTParty.get("#{API_ROOT}#{TOKEN_PATH}",
32
+ cookies: {KinjaSession: session_token(response)}
33
+ )['data']['token']
34
+ end
35
+
36
+ def session_token(response)
37
+ re = /KinjaSession=([\w-]+);/
38
+ response.headers["set-cookie"].match(re)[1]
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,56 @@
1
+ module Kinja
2
+ module Helper
3
+ def get_post_id(link)
4
+ return link if link.match(/^\d+$/)
5
+ new_link_re = /-(\d{8,11})\/?/
6
+ old_link_re = /\.com\/(\d+)\//
7
+ return link.match(new_link_re)[1] if link.match(new_link_re)
8
+ return link.match(old_link_re)[1] if link.match(old_link_re)
9
+ end
10
+
11
+ private
12
+ API_ROOT = "http://kinja.com/api"
13
+ LOGIN_PATH = "/profile/account/burner/login"
14
+ TOKEN_PATH = "/profile/token"
15
+ CREATE_POST_PATH = "/core/post/add"
16
+ POST_PATH = "core/post"
17
+ BLOG_PATH = "core/blog"
18
+ TAG_PATH = "core/tag"
19
+ BLOG_PROFILE_PATH = "profile/blog/byhost"
20
+ AUTHOR_PATH = "profile/user/views/asAuthor"
21
+
22
+ def post_path(id)
23
+ "#{API_ROOT}/#{POST_PATH}/#{id}"
24
+ end
25
+
26
+ def create_post_path
27
+ "#{API_ROOT}#{CREATE_POST_PATH}?token=#{@api_token}"
28
+ end
29
+
30
+ def update_post_path(id)
31
+ "#{API_ROOT}#{POST_PATH}/#{id}/update?token=#{@api_token}"
32
+ end
33
+
34
+
35
+ def blog_latest_by_id_path(id)
36
+ "#{API_ROOT}/#{BLOG_PATH}/#{id}/latest"
37
+ end
38
+ def blog_profile_path(name)
39
+ "#{API_ROOT}/#{BLOG_PROFILE_PATH}/#{name}"
40
+ end
41
+
42
+ def tag_path(name)
43
+ "#{API_ROOT}/#{TAG_PATH}/#{URI.encode name}"
44
+ end
45
+
46
+ def tag_and_blog_path(name, blog_id)
47
+ "#{API_ROOT}/#{BLOG_PATH}/#{blog_id}/tag/#{URI.encode name}"
48
+ end
49
+
50
+ def author_path(id)
51
+ "#{API_ROOT}/#{AUTHOR_PATH}?ids=#{id}"
52
+ end
53
+
54
+ end
55
+ end
56
+
data/lib/kinja/post.rb ADDED
@@ -0,0 +1,36 @@
1
+ module Kinja
2
+ module Post
3
+ def get_post(link_or_id)
4
+ id = get_post_id link_or_id
5
+ HTTParty.get post_path(id)
6
+ end
7
+
8
+ def create_post(opts={})
9
+ get_api_token(login)
10
+ opts[:status] = opts[:status] || "DRAFT"
11
+ opts[:replies] = opts[:replies] || true
12
+ opts[:defaultBlogId] = opts[:defaultBlogId] || get_default_blog_id(@user)
13
+
14
+ HTTParty.post create_post_path,
15
+ body: {
16
+ headline: opts[:headline],
17
+ original: opts[:body],
18
+ defaultBlogId: opts[:defaultBlogId],
19
+ status: opts[:status],
20
+ allowReplies: opts[:replies]
21
+ }.to_json,
22
+ headers: { 'Content-Type' => 'application/json' }
23
+ end
24
+
25
+ def update_post(link_or_id, opts)
26
+ get_api_token(login)
27
+
28
+ id = get_post_id link_or_id
29
+ opts[:defaultBlogId] = opts[:defaultBlogId] || get_default_blog_id(@user)
30
+ HTTParty.post update_post_path(id),
31
+ body: opts.to_json,
32
+ headers: { 'Content-Type' => 'application/json' }
33
+ end
34
+
35
+ end
36
+ end
data/lib/kinja/tag.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Kinja
2
+ module Tag
3
+ def tag(name, blog=nil)
4
+ if blog.nil?
5
+ feed = get_posts_in_tag(name)
6
+ else
7
+ feed = get_posts_in_tag_for_site(name, blog)
8
+ end
9
+ if feed["meta"]["success"]
10
+ feed["data"]["items"]
11
+ else
12
+ feed
13
+ end
14
+ end
15
+
16
+ def get_posts_in_tag(name)
17
+ HTTParty.get tag_path(name)
18
+ end
19
+
20
+ def get_tag_feed_for_site(name, blog_id)
21
+ HTTParty.get tag_and_blog_path(name, blog_id)
22
+ end
23
+
24
+ def get_posts_in_tag_for_site(name, blog_name_or_id)
25
+ if blog_name_or_id.is_a? String
26
+ get_tag_feed_for_site name, get_blog_id(blog_name_or_id)
27
+ else
28
+ get_tag_feed_for_site(name, blog_name_or_id)
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+
data/lib/kinja/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Kinja
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/lib/kinja.rb CHANGED
@@ -1,87 +1,11 @@
1
- require "kinja/version"
2
- require 'httparty'
1
+ require 'kinja/client'
3
2
 
4
3
  module Kinja
5
- class Client
6
- attr_accessor :user
4
+ autoload :VERSION, File.join(File.dirname(__FILE__), 'kinja/version')
7
5
 
8
- API_ROOT = "http://kinja.com/api"
9
- LOGIN_PATH = "/profile/account/burner/login"
10
- TOKEN_PATH = "/profile/token"
11
- CREATE_POST_PATH = "/core/post/add"
12
- POST_PATH = "/core/post"
13
- AUTHOR_PATH = "/profile/user/views/asAuthor"
14
-
15
- def initialize(opts={})
16
- if opts.has_key? :user and opts.has_key? :password
17
- @username = opts[:user]
18
- @pass = opts[:password]
19
- end
20
- end
21
-
22
- def create_post(opts={})
23
- get_api_token(login)
24
- opts[:status] = opts[:status] || "DRAFT"
25
- opts[:replies] = opts[:replies] || true
26
- opts[:defaultBlogId] = opts[:defaultBlogId] || get_default_blog_id(@user)
27
-
28
- HTTParty.post "#{API_ROOT}#{CREATE_POST_PATH}?token=#{@api_token}",
29
- body: {
30
- headline: opts[:headline],
31
- original: opts[:body],
32
- defaultBlogId: opts[:defaultBlogId],
33
- status: opts[:status],
34
- allowReplies: opts[:replies]
35
- }.to_json,
36
- headers: { 'Content-Type' => 'application/json' }
37
- end
38
-
39
- def update_post(link_or_id, opts)
40
- get_api_token(login)
41
-
42
- id = get_post_id link_or_id
43
- opts[:defaultBlogId] = opts[:defaultBlogId] || get_default_blog_id(@user)
44
- HTTParty.post "#{API_ROOT}#{POST_PATH}/#{id}/update?token=#{@api_token}",
45
- body: opts.to_json,
46
- headers: { 'Content-Type' => 'application/json' }
47
- end
48
-
49
- def get_post(link_or_id)
50
- id = get_post_id link_or_id
51
- HTTParty.get "#{API_ROOT}#{POST_PATH}/#{id}"
52
- end
53
-
54
- def get_post_id(link)
55
- return link if link.match(/^\d+$/)
56
- new_link_re = /-(\d{8,11})\/?/
57
- old_link_re = /\.com\/(\d+)\//
58
- return link.match(new_link_re)[1] if link.match(new_link_re)
59
- return link.match(old_link_re)[1] if link.match(old_link_re)
60
- end
61
-
62
- def get_author(user)
63
- HTTParty.get "#{API_ROOT}#{AUTHOR_PATH}?ids=#{user["id"]}"
64
- end
65
-
66
- def get_default_blog_id(user)
67
- get_author(user)["data"][0]["defaultBlogId"]
68
- end
69
-
70
- def login
71
- response = HTTParty.get "#{API_ROOT}#{LOGIN_PATH}?screenName=#{@username}&token=#{@pass}"
72
- @user = response["data"]
73
- response
74
- end
75
-
76
- def get_api_token(response)
77
- @api_token = HTTParty.get("#{API_ROOT}#{TOKEN_PATH}",
78
- cookies: {KinjaSession: session_token(response)}
79
- )['data']['token']
80
- end
81
-
82
- def session_token(response)
83
- re = /KinjaSession=([\w-]+);/
84
- response.headers["set-cookie"].match(re)[1]
6
+ class << self
7
+ def new(options={})
8
+ Kinja::Client.new(options)
85
9
  end
86
10
  end
87
11
  end
@@ -0,0 +1,67 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://kinja.com/api/profile/user/views/asAuthor?ids=5716491910670767033
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Access-Control-Allow-Headers:
22
+ - Content-Type
23
+ Access-Control-Allow-Methods:
24
+ - POST, GET, OPTIONS, PUT, DELETE
25
+ Access-Control-Allow-Origin:
26
+ - "*"
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ X-Kinja:
30
+ - 'app05.xyz.kinja-ops.com #1178'
31
+ X-Kinja-Version:
32
+ - '20141118'
33
+ X-Robots-Tag:
34
+ - noindex
35
+ X-Cdn-Fetch:
36
+ - mantle-origin-cache
37
+ Content-Length:
38
+ - '188'
39
+ Accept-Ranges:
40
+ - none
41
+ Date:
42
+ - Tue, 14 Apr 2015 13:42:56 GMT
43
+ Via:
44
+ - 1.1 varnish
45
+ Age:
46
+ - '5'
47
+ Connection:
48
+ - keep-alive
49
+ X-Served-By:
50
+ - cache-jfk1024-JFK
51
+ X-Cache:
52
+ - HIT
53
+ X-Cache-Hits:
54
+ - '1'
55
+ X-Timer:
56
+ - S1429018976.317220,VS0,VE0
57
+ Vary:
58
+ - X-Feature-Hash,Accept-Encoding
59
+ Set-Cookie:
60
+ - geocc=US;path=/;
61
+ body:
62
+ encoding: ASCII-8BIT
63
+ string: '{"meta":{"error":null,"warnings":[]},"data":[{"id":"5716491910670767033","screenName":"adampash","displayName":"Adam
64
+ Pash","superUser":false,"defaultBlogId":771,"avatar":{"id":"gdjxua361big4hslpfhx","format":"png"}}]}'
65
+ http_version:
66
+ recorded_at: Tue, 14 Apr 2015 13:42:58 GMT
67
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,67 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://kinja.com/api/profile/user/views/asAuthor?ids=5716491910670767033
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Access-Control-Allow-Headers:
22
+ - Content-Type
23
+ Access-Control-Allow-Methods:
24
+ - POST, GET, OPTIONS, PUT, DELETE
25
+ Access-Control-Allow-Origin:
26
+ - "*"
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ X-Kinja:
30
+ - 'app14.xyz.kinja-ops.com #1178'
31
+ X-Kinja-Version:
32
+ - '20141118'
33
+ X-Robots-Tag:
34
+ - noindex
35
+ X-Cdn-Fetch:
36
+ - mantle-origin-cache
37
+ Content-Length:
38
+ - '188'
39
+ Accept-Ranges:
40
+ - none
41
+ Date:
42
+ - Mon, 13 Apr 2015 22:06:32 GMT
43
+ Via:
44
+ - 1.1 varnish
45
+ Age:
46
+ - '0'
47
+ Connection:
48
+ - keep-alive
49
+ X-Served-By:
50
+ - cache-jfk1033-JFK
51
+ X-Cache:
52
+ - MISS
53
+ X-Cache-Hits:
54
+ - '0'
55
+ X-Timer:
56
+ - S1428962792.353481,VS0,VE8
57
+ Vary:
58
+ - X-Feature-Hash,Accept-Encoding
59
+ Set-Cookie:
60
+ - geocc=US;path=/;
61
+ body:
62
+ encoding: ASCII-8BIT
63
+ string: '{"meta":{"error":null,"warnings":[]},"data":[{"id":"5716491910670767033","screenName":"adampash","displayName":"Adam
64
+ Pash","superUser":false,"defaultBlogId":771,"avatar":{"id":"gdjxua361big4hslpfhx","format":"png"}}]}'
65
+ http_version:
66
+ recorded_at: Mon, 13 Apr 2015 22:06:35 GMT
67
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,68 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://kinja.com/api/profile/blog/byhost/gawker.com
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Access-Control-Allow-Headers:
22
+ - Content-Type
23
+ Access-Control-Allow-Methods:
24
+ - POST, GET, OPTIONS, PUT, DELETE
25
+ Access-Control-Allow-Origin:
26
+ - "*"
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ X-Kinja:
30
+ - 'app17.xyz.kinja-ops.com #1178'
31
+ X-Kinja-Version:
32
+ - '20141118'
33
+ X-Robots-Tag:
34
+ - noindex
35
+ X-Cdn-Fetch:
36
+ - mantle-origin-cache
37
+ Content-Length:
38
+ - '673'
39
+ Accept-Ranges:
40
+ - none
41
+ Date:
42
+ - Mon, 13 Apr 2015 21:01:23 GMT
43
+ Via:
44
+ - 1.1 varnish
45
+ Age:
46
+ - '0'
47
+ Connection:
48
+ - keep-alive
49
+ X-Served-By:
50
+ - cache-jfk1031-JFK
51
+ X-Cache:
52
+ - MISS
53
+ X-Cache-Hits:
54
+ - '0'
55
+ X-Timer:
56
+ - S1428958883.121019,VS0,VE8
57
+ Vary:
58
+ - X-Feature-Hash,Accept-Encoding
59
+ Set-Cookie:
60
+ - geocc=US;path=/;
61
+ body:
62
+ encoding: ASCII-8BIT
63
+ string: '{"meta":{"error":null,"warnings":[]},"data":{"id":7,"name":"gawker","displayName":"Gawker","canonicalHost":"gawker.com","hosts":["newfeedgawker.kinja.com","de.gawker.com","au.gawker.com","us.gawker.com","m.gawker.com","br.gawker.com","newsfeed.gawker.com","ru.gawker.com","www.gawker.com","ads.gawker.com","blog.gawker.com","assets.gawker.com","ca.gawker.com","uk.gawker.com","cityfile.gawker.com","fetch.gawker.com","nl.gawker.com","es.gawker.com"],"status":"ENABLED","createTimeMillis":1354577923124,"lastUpdateTimeMillis":1428428881357,"createdById":"7","ownerId":"5722373954280962685","description":"Today''s
64
+ gossip is tomorrow''s news","descriptionHtml":null,"mergedProperties":{"aboutPostId":1679006931,"showInsets":true,"fbAppId":"447084078690870","metaTitle":"Gawker
65
+ &mdash; Today''s gossip is tomorrow''s news","googleSiteVerification":"PMODv5fOfI_I6GRn06P6uDSnTPLgipc_fgkmh7EgXyw","blogGroup":"gawker","isGmgBlog":true,"googleAnalyticsID":"UA-142218-2","kruxId":"JMWgLQaa","template":"gawker"},"showLikesInLatest":false,"showRepliesInLatest":false,"timezone":"America/New_York","timezoneOffset":-14400000,"timezoneShortname":"EDT","avatar":{"id":"duyy8bbxv1j5xi3spt5n","format":"jpg"},"logo":{"id":"ztcaspqy4mjgehh3o09r","format":"png"},"groupBlog":true,"noindex":false}}'
66
+ http_version:
67
+ recorded_at: Mon, 13 Apr 2015 21:01:26 GMT
68
+ recorded_with: VCR 2.9.3