Skip to content

Commit

Permalink
Merge pull request #2032 from sparc-request/kg-fix_news_feed
Browse files Browse the repository at this point in the history
KG - Add News Feed API Token For Atlassian API
  • Loading branch information
Stuart-Johnson committed Oct 8, 2019
2 parents 7d30b8e + d0549bd commit 8bf70d2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
9 changes: 5 additions & 4 deletions app/lib/news_feed/api_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@

module NewsFeed
class ApiAdapter < NewsFeed::Base
def initialize(api_string="", content_type='application/json', parameters={limit: NewsFeed::Base::POST_LIMIT})
@content_type = content_type
@parameters = parameters
def initialize(api_string, opts={})
@content_type = opts[:content_type] || 'application/json'
@headers = opts[:headers] || { 'Content-Type' => @content_type }
@parameters = opts[:parameters] || {limit: NewsFeed::Base::POST_LIMIT}
@url = NewsFeed::Base::BASE_URL + api_string + parameter_string
end

Expand All @@ -31,7 +32,7 @@ def add_parameter(key, value)
end

def get
HTTParty.get(@url, headers: { 'Content-Type' => @content_type })
HTTParty.get(@url, headers: @headers)
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/lib/news_feed/atlassian_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize
space = Setting.get_value("news_feed_atlassian_space")
params = { limit: limit, expand: 'version', cql: "space=#{space} AND type=blogpost order by created desc" }

super(api_string, 'application/json', params)
super(api_string, headers: { 'Content-Type' => 'application/json', 'Authorization' => "Basic #{NewsFeed::Base::API_TOKEN}" }, parameters: params)
end

def posts
Expand Down
1 change: 1 addition & 0 deletions app/lib/news_feed/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module NewsFeed
class Base
BASE_URL = Setting.get_value('news_feed_url')
POST_LIMIT = Setting.get_value('news_feed_post_limit')
API_TOKEN = Setting.get_value('news_feed_api_token')

# Abstract Method
#
Expand Down
10 changes: 10 additions & 0 deletions config/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,16 @@
"parent_key": "use_news_feed_api",
"parent_value": "true"
},
{
"key": "news_feed_api_token",
"value": "aGV3d2VAbXVzYy5lZHU6UWZ1ZUpldG9ydEZlMDBwcFVCandCMUEz",
"friendly_name": "News Feed API Token",
"description": "This is the optional token used by the News Feed API to retrieve posts.<br>For Atlassian API Tokens, see https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/.",
"group": "",
"version": "",
"parent_key": "use_news_feed_api",
"parent_value": "true"
},
{
"key": "news_feed_atlassian_space",
"value": "RD",
Expand Down

0 comments on commit 8bf70d2

Please sign in to comment.