Skip to content

Commit

Permalink
Merge pull request #2 from andygeers/ag-sessions
Browse files Browse the repository at this point in the history
Authentication for updating feeds
  • Loading branch information
UsAndRufus authored Jun 1, 2018
2 parents a144e57 + 566f3c2 commit db2c0e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
31 changes: 25 additions & 6 deletions lib/prayermate_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ module PrayerMateApi
class PrayerMateApiException < RuntimeError
end

def self.build_session(email, api_token)
{
email: email,
api_token: api_token
}
end

def self.api(protocol, host, api_key, session = nil)
PrayerMateApi::Api.new protocol, host, api_key, session
end
Expand Down Expand Up @@ -44,15 +51,25 @@ def register(promo_code, first_name, last_name, email, roles)
end

def update_input_feed(feed_id, user_feed_slug, petitions, last_modified)
HTTParty.post(api_path("input_feeds/process"),
body: { feed: { id: feed_id, user_feed_slug: user_feed_slug, last_modified: last_modified }, petitions: petitions },
headers: http_headers)
post_with_auth("input_feeds/process", {
feed: {
id: feed_id,
user_feed_slug: user_feed_slug,
last_modified: last_modified
},
petitions: petitions
})
end

def update_user_feed(feed_id, petitions, last_modified, url)
HTTParty.post(api_path("feeds/process"),
body: { feed: { id: feed_id, last_modified: last_modified, static_json_url: url }, petitions: petitions },
headers: http_headers)
post_with_auth("feeds/process", {
feed: {
id: feed_id,
last_modified: last_modified,
static_json_url: url
},
petitions: petitions
})
end

def post_with_auth(endpoint, data)
Expand Down Expand Up @@ -88,6 +105,8 @@ def process_response(response)
end

def auth_hash
return nil if session_token.nil?

{ username: email, password: session_token }
end

Expand Down
2 changes: 1 addition & 1 deletion lib/prayermate_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module PrayerMateApi
VERSION = "0.1.3"
VERSION = "0.2.0"
end

0 comments on commit db2c0e7

Please sign in to comment.