AP - Associated Press API Gem
This is a Ruby API wrapper for the Assosciated Press API v2. This code was based on version 1.1 of the documentation, which was last revised 06/15/2010
Usage
require 'ap'
AP.configure do |config|
config.api_key = "your_api_key"
end
# Categories & Articles
categories = AP.categories
=> [#<AP::Category:0x10226e118 @content="AP Online Top General Short Headlines", @id="category id", @title="AP Online Top General Short Headlines", @updated=Sat Apr 30 01:25:10 UTC 2011>, ....]
category = categories.first
=> #<AP::Category:0x10226e118 @content="AP Online Top General Short Headlines", @id="category id", @title="AP Online Top General Short Headlines", @updated=Sat Apr 30 01:25:10 UTC 2011>
articles = category.articles
=> [#<AP::Article:0x101e15440 @content="...html content..." @id="...AP Article ID....", @tags=["Property damage", "Tornados", "Humanitarian crises", ..., "North America"], @link="...link to AP hosted version...", @title="...article title...", @updated=Sat Apr 30 00:07:01 UTC 2011, @authors=["Author 1", "Author 2"]>
articles.first.similar
=> #<AP::Search:0x1018aa618 @query={:count=>20, :searchTerms=>"...article id...", :startPage=>1}, @search_type="similar", @total_results=0>
# Searching
search = AP::Search.new
=> #<AP::Search:0x1018bb760 @query={:count=>20, :searchTerms=>[], :startPage=>1}, @search_type="request", @total_results=0>
search.contains("Obama").and.contains("Iraq")
=> #<AP::Search:0x101891870 @query={:count=>20, :searchTerms=>["Obama", "AND", "Iraq"], :startPage=>1}, @search_type="request", @total_results=0>
search.fetch
=> An array of AP::Articles
search.next_page?
=> true
search.next_page
=> An array of AP::Articles
search.clear
search.scoped do |s|
s.contains("Obama").or.contains("Iraq")
end.and.contains("Iran")
search.to_s
=> "( Obama OR Iraq ) AND Iran"
Why is all the inofrmation missing? I’m not sure exactly what I can share, so I’m being careful. Either way it gets the information across.
Contributing to ap
-
Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
-
Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
-
Fork the project
-
Start a feature/bugfix branch
-
Commit and push until you are happy with your contribution
-
Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright
Copyright © 2011 Alex Coomans. See LICENSE.txt for further details.