I'm working on a little Ruby program to collect GitHub URLs from my Pocket account and then star those repos on my GitHub account. I've been able to connect to Pocket's API and get the URLs from my feed, but I'm having trouble with my requests to the "https://api.github.com/user/starred" endpoint.
This is what I'm using
I initially used Paw on my Mac to get the authorization tokens for both Pocket and GitHub - the Pocket API is working perfectly in both Paw and in my Rub, but the GitHub request is only working in Paw.
I've tried both flavors of the Faraday request syntax (you can see them in the code), using Faraday.new and a simple Faraday.get
require 'faraday'
require 'json'
github = Faraday.new(
url: 'https://api.github.com/user/starred',
headers: {
'Accept ': 'application/vnd.github.v3+json',
'Authorization': 'Bearer ***SUPER_SECRET_SAUCE***',
'User-Agent': 'jriggles'
}
)
pocket = Faraday.get(
'https://getpocket.com/v3/get?consumer_key=***MY_POCKET_KEY**&access_token=***MY_POCKET_TOKEN***&contentType=article&detailType=simple&sort=newest&domain=github.com&count=100',
'Content-Type': 'application/json; charset=UTF8',
'X-Accept': 'application/json',
'User-Agent': 'jriggles'
)
if pocket.status == 200
parsed_response = JSON.parse(pocket.body)
parsed_response['list'].each do |_key, val|
owner = val['given_url'].split('/')[3]
repo = val['given_url'].split('/')[4]
puts github.get("/#{owner}/#{repo}").status
end
else puts "Connection to Pocket failed - Code #{pocket.status}"
end
This is the line that's returning the HTTP status codes:
puts github.get("#{owner}/#{repo}").status
I've tried a few permutations, and I've only been getting [401], [403], and in this current iteration [400]. I'm not sure if it's an issue with my GitHub authorization or with my Faraday syntax, or both.