Google CivicInfo API Zip Codes for PR - ruby

I am trying to use the Civic Info API V2 to replace the now-defunct Sunlight Labs Congressional Legislator API. To do this I am passing an zip code string as the address into the Google API. However, when I try to pass the zip code for a Puerto Rico address, "00924" I'm returned a 404 - No information for this address. I get the same error when I add the city to the query, San+Juan+PR+00924. Puerto Rico has one Delegate Representative in the US House of Reps.
I'm using ruby's google-api-client gem to access the API in my program, but I get the same errors using the web API. Other zip codes work - just having troubles with this one.
Can anyone help me figure out how to get Delegate's name and information using this API?
EDIT: My current ruby code
def legislators_by_zip_code(zip)
civic_info = Google::Apis::CivicinfoV2::CivicInfoService.new
civic_info.key = '<My API Key>'
return if zip == "00000"
legislators = civic_info.representative_info_by_address(
address: zip,
levels: 'country',
roles: ['legislatorUpperBody', 'legislatorLowerBody'])
end

Related

How to access Clockify API through Power Query

I am trying to get my time entries from Clockify API directly via Power Query to Excel. I use the following code in the Power Query:
= Web.Contents("https://api.clockify.me/api/workspaces/ID of my workspace/timeEntries/", [
Query=[ #"filter"="", #"orderBy"=""],
ApiKeyName="APIToken"
])
When I then try to run the code I am prompted to enter the Web API authentification, which delivers an error ("English translation: Authentification does not work. Try again") after I enter my correct Web API code see screenshot here
Does anyone have an idea how to solve this?
There are two things to keep in mind when making calls to REST-based APIs in Power Query/M:
When using the Web.Contents() function, it's best to pass your API key as a parameter within the request header itself. In your case X-Api-Key should equal to {your API key}.
Use anonymous access to connect to the API. Your screenshot suggests you're trying to connect using "Web API". Clear the value in the "Schlüssel" field and use "Anonym" instead.
Here's a simple example where I return the information about a workspace by workspace ID. (I've masked both my workspace ID and API key; replace these values with your workspace ID and API key.)
This works for me in both Excel and Power BI:
let
Source =
Web.Contents(
"https://api.clockify.me/api/workspaces/{your workspace ID}",
[
Headers=[
#"Content-Type"="application/json",
#"X-Api-Key"={your API key}
]
]
),
jsonResponse = Json.Document(Source)
in
jsonResponse
Doesn't it have to be X-Api-Key instead of ApiKeyName?

Download my own private albums using Flickr API

I'm trying to download my own flickr albums using the API. I'm using the flickr.rb gem here
I am creating a new object using this:
#flickr = Flickr.new({api_key: 'xxxxx', shared_secret: 'xxxxx', verify_ssl: false})
And then I'm using:
p = #flickr.photoset(photoset_id)
Where I pass the id of my photoset I want to download.
I keep getting the error:
/.rvm/gems/ruby-2.2.5/gems/flickr.rb-1.2.1/lib/flickr.rb:199:in `request': Photoset not found (RuntimeError)
What is the correct way to authenticate to Flickr and download my photos? I don't want to build any UI, just want a command line app to do this. Is there some URL I need to hit in the browser to authorize the app and grant permissions? The documentation is really sparse and doesn't give any examples.
Update: In response to #r-f-nelson
The 'user' as retrieved:
#Flickr::User:0x007fd8cea6ad98 #id="29916617#N02", #username="taraporefarhad", #client=#<Flickr:0x007fd8cf09fc68 #host="https://api.flickr.com", #api="/services/rest", #verify_ssl=false, #api_key="36705xxxxxxxxxxxxxxx", #shared_secret="xxxxxxxxxxxxxx", #auth_token=nil, #ca_file=nil
The 'flickr' client object:
#Flickr:0x007fd8cf09fc68 #host="https://api.flickr.com", #api="/services/rest", #verify_ssl=false, #api_key="36705xxxxxxxxxxxxxxx", #shared_secret="xxxxxxxxxxxxxx", #auth_token=nil, #ca_file=nil, #user=#
Flickr::User:0x007fd8cea6ad98 #id="29916617#N02", #username="taraporefarhad", #client=#<Flickr:0x007fd8cf09fc68 ...
The Photoset object:
#Flickr::Photoset:0x007fd8cf06c9d0 #id="72157638843727066", #api_key=nil, #client=#<Flickr:0x007fd8cf06c8b8 #host="https://api.flickr.com", #api="/services/rest", #verify_ssl=true, #api_key=nil, #shared_secret=nil, #auth_token=nil, #ca_file=nil
/.rvm/gems/ruby-2.2.5/gems/flickr.rb-1.2.1/lib/flickr.rb:199:in `request': Invalid API Key (Key has invalid format) (RuntimeError)
Note above that the "photoset" object has a different flickr client object id and NO shared secret and API key! Not sure how that's happening since I'm using the same client and user objects to get the photoset as well.
Assuming you are successfully connecting to Flickr's API, you can browse your own photosets like so:
user = flickr.users('you#yourflickraccount.com')
photosets = user.photosets
From there you can iterate through your photosets to find the correct one. I'm guessing whatever id you're using is not the actual photoset_id that the Flickr API uses.

Google Contacts feed is breaking gdata-contacts-3.0-1.47.1

This is for Google API folks.
Not sure when exactly the feed has changed but very recently (today or a couple of days ago). the GDATA library can't process Google Contacts feed anymore, failing with this:
com.yoxel.sync.core.exceptions.SyncException: com.google.gdata.util.ParseException: [Line 30, Column 86, element gContact:website] Invalid value for attribute : 'rel'
value=http://schemas.google.com/g/2005#profile
GDATA library seems to be expecting capital PROFILE but the feed started to send lowercase!
for (Enum enumValue : (Enum[])enumClass.getEnumConstants()) {
if (enumToAttributeValue.getAttributeValue(enumValue).equals(value){
return enumValue;
}
}
Is there more recent gdata library available?
Thank you.
10/9/20 Update:
For those migrating to the new People API check out our new unified API platform Aurinko.io
Seems like Google contacts feed API is currently broken when creating/updating contacts if a contact has relations/events/websites.
Ticket is already filed at https://issuetracker.google.com/u/0/issues/70209603
It appears that Google has now corrected the problem.

Sabre Dev Studio API call by ruby

I'm trying to take hotels details from sabre dev studio in my app and I'm using gem 'sabre_dev_studio' but I can't understand how and which url I have to hit (APIs) for the hotel details. I'm using like this :
SabreDevStudio.configure do |c|
c.client_id = 'V1:kiifsurie29jj:KITPUI:DFR'
c.client_secret = 'wiurRTs'
c.uri = 'https://api.test.sabre.com'
end
token = SabreDevStudio::Base.get_access_token
themes = SabreDevStudio::Base.get('/v1/shop/themes')
this is working and give me proper response but for hotels I'm not getting which url are for apies.
https://developer.sabre.com/docs/read/rest_basics/endpoints_and_uris
This is the list of the urls you'll want
There are currently no REST APIs for hotels, only SOAP at the moment.
Here's the related documentation:
https://developer.sabre.com/docs/read/soap_apis/hotel

Accessing entire netflix catalog via API v1.5

Netflix recently updated their API methods for obtaining the full Netflix catalog. I'm curious if anyone has had any success accessing these new xml documents and downloading them via API v1.5 (9/2012). Previously, you could download the entire Netflix catalog via one API call (which I had working perfectly). Now, there are supposedly two calls to make: one for dvd's and one for streaming movies.
I cannot make these calls return anything except for an empty array. Please don't offer an answer unless you have personally downloaded the entire catalog via these new API's.
Bonus points if you can tell me how to do it in Ruby.
http://developer.netflix.com/blog/read/Update_Changes_for_the_Public_API
This did it for me (download the netflix instant cat)...it's in php but can prob be easily rewritten in ruby..this is using JR Collings OAuthsimple
args = Array(
max_results=> 20,
start_index=>0
);
//args don't matter, netflix doesn't listen here
// this is the URL path (note the lack of arguments.)
$rpath = "http://api-public.netflix.com/catalog/titles/streaming";
// Create the Signature object.
$roauth = new OAuthSimple();
$rsigned = $roauth->sign(Array(path=>$rpath,
parameters=>$args,
signatures=> Array('consumer_key'=>YOURKEY,
'shared_secret'=>YOURSECRET,
)));
$getxml = file_get_contents($rsigned['signed_url']);
file_put_contents("streaming.xml", $getxml);

Resources