lib/livefyre/core.rb in livefyre-1.0.0 vs lib/livefyre/core.rb in livefyre-1.1.0
- old
+ new
@@ -1,6 +1,7 @@
require 'base64'
+require 'digest'
require 'json'
require 'jwt'
require 'rest-client'
require 'uri'
@@ -18,25 +19,25 @@
raise ArgumentError, 'url_template should contain {id}' if !url_template.include?('{id}')
response =
RestClient.post(
"http://#{@network_name}",
- { actor_token: build_lf_token, pull_profile_url: url_template }
+ { actor_token: build_livefyre_token, pull_profile_url: url_template }
)
response.code == 204
end
def sync_user(user_id)
response =
RestClient.post(
"http://#{@network_name}/api/v3_0/user/#{user_id}/refresh",
- { lftoken: build_lf_token }
+ { lftoken: build_livefyre_token }
)
response.code == 200
end
- def build_lf_token
+ def build_livefyre_token
build_user_auth_token(DEFAULT_USER, DEFAULT_USER, DEFAULT_EXPIRES)
end
def build_user_auth_token(user_id, display_name, expires)
raise ArgumentError, 'user_id must be alphanumeric' if !(user_id =~ /\A\p{Alnum}+\z/)
@@ -66,28 +67,40 @@
@network_name = network_name
@site_id = site_id
@site_key = site_key
end
- def build_collection_meta_token(title, article_id, url, tags, stream='')
+ def build_collection_meta_token(title, article_id, url, tags='', stream=nil)
raise ArgumentError, 'provided url is not a valid url' if !uri?(url)
raise ArgumentError, 'title length should be under 255 char' if title.length > 255
- JWT.encode({
- title: title,
- url: url,
- tags: tags,
- articleId: article_id,
- type: stream},
- @site_key)
+
+ collection_meta = { url: url, tags: tags, title: title }
+ checksum = Digest::MD5.new.update(collection_meta.to_json).hexdigest
+
+ collection_meta[:articleId] = article_id
+ collection_meta[:checksum] = checksum
+
+ if stream
+ collection_meta[:type] = stream
+ end
+
+ JWT.encode(collection_meta, @site_key)
end
def get_collection_content(article_id)
response =
RestClient.get(
"http://bootstrap.#{@network_name}/bs3/#{@network_name}/#{@site_id}/#{Base64.encode64(article_id.to_s()).chomp}/init",
:accepts => :json
)
response.code == 200 ? JSON.parse(response) : nil
+ end
+
+ def get_collection_id(article_id)
+ content = get_collection_content(article_id)
+ if content
+ content['collectionSettings']['collectionId']
+ end
end
def uri?(string)
uri = URI.parse(string)
%w( http https ).include?(uri.scheme)
\ No newline at end of file