fcc-content-api 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fcc-content-api.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ The FCC Content API allows you to programmatically access much of the content accessible on [FCC.gov](http://fcc.gov).
2
+
3
+ fcc-content-api is a lightweight Ruby wrapper for the Federal Communication Commission's Content API. The query interface resembles ActiveRecord. The response objects are simple Ruby `Hash`es and `Array`s.
4
+
5
+ The FCC Content API is powered by the [Drupal Content API Module](http://drupal.org/project/contentapi).
6
+
7
+ ## Usage
8
+
9
+ First, familiarize yourself with the [FCC Content API REST Documentation](http://www.fcc.gov/developer/fcc-content-api).
10
+
11
+ The `FccContentApi::Content` object is where you'll do most of the querying.
12
+
13
+ ```ruby
14
+ results = FccContentApi::Content.where(:search_string => "broadband").all
15
+ results.first # => {"count"=>"587", "pages"=>58, "itemsPerPage"=>10, "currentPage"=>0}
16
+ results[1] # => {"nid"=>"38802", "title"=>"PSHSB Seeks Comment on Broadband Waiver Transition Process", "created"=>"2012-04-06", "changed"=>"2012-04-09", "type"=>"edoc", "webUrl"=>"http://www.fcc.gov/document/pshsb-seeks-comment-broadband-waiver-transition-process", "uri"=>"http://www.fcc.gov/api/content/38802"}
17
+ ```
18
+
19
+ Options for `FccContentApi#where` map 1-to-1 to the query options listed in the official [FCC docs](http://www.fcc.gov/developer/fcc-content-api).
20
+
21
+ For example, if you want proceedings, related edocs and comments:
22
+
23
+ ```ruby
24
+ FccContentApi::Content.where(:edocs => "true").where(:type => "proceeding").where(:comments => "true").all
25
+
26
+ # or pass a single Hash:
27
+ FccContentApi::Content.where({:edocs => "true", :type => "proceeding" :comments => "true"}).all
28
+ ```
29
+
30
+ ## Installation
31
+
32
+ `gem install fcc-content-api` or:
33
+
34
+ ```ruby
35
+ # Gemfile
36
+ gem "fcc-content-api"
37
+ ```
38
+
39
+ ## More Info
40
+
41
+ For more information, please visit the [FCC's Developers page](http://www.fcc.gov/developers) and the [FCC's Github page](http://github.com/fcc).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "fcc-content-api/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "fcc-content-api"
7
+ s.version = FccContentApi::VERSION
8
+ s.authors = ["Alan deLevie"]
9
+ s.email = ["adelevie@gmail.com"]
10
+ s.homepage = "http://github.com/adelevie"
11
+ s.summary = %q{A Ruby wrapper for the FCC's Content API}
12
+ s.description = %q{A Ruby wrapper for the FCC's Content API}
13
+
14
+ s.rubyforge_project = "fcc-content-api"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "vcr"
23
+ s.add_development_dependency "webmock", ">= 1.8.0"
24
+ s.add_runtime_dependency "weary"
25
+ end
@@ -0,0 +1,3 @@
1
+ module FccContentApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,72 @@
1
+ require "fcc-content-api/version"
2
+ require "weary"
3
+ require "json"
4
+
5
+ module FccContentApi
6
+
7
+ def self.client
8
+ @@client ||= FccContentApi::Client.new
9
+ end
10
+
11
+ class Content
12
+ def self.where(*args)
13
+ Query.new(self).where(*args)
14
+ end
15
+
16
+ def self.all
17
+ Query.new(self).all
18
+ end
19
+
20
+ def self.find(id)
21
+ resp = FccContentApi::Client.new.get(:id => id).perform.body
22
+ JSON.parse resp
23
+ end
24
+ end
25
+
26
+ class Query
27
+
28
+ def initialize(klass); @klass = klass; end
29
+
30
+ def criteria; @criteria ||= {}; end
31
+
32
+ def where(args)
33
+ criteria.merge! args
34
+ self
35
+ end
36
+
37
+ def all; execute; end
38
+
39
+ def request
40
+ @request ||= FccContentApi::Client.new.all criteria
41
+ end
42
+
43
+ def execute
44
+ resp = request.perform.body
45
+ JSON.parse(resp)
46
+ end
47
+
48
+ end
49
+
50
+ class Client < Weary::Client
51
+ domain "http://www.fcc.gov/api"
52
+
53
+ get :all, "/content.json?" do |resource|
54
+ resource.optional :created_before, :created_after, # YYYY-MM-DD
55
+ :changed_before, :changed_after, # YYYY-MM-DD
56
+ :search_string,
57
+ :limit,
58
+ :page,
59
+ :fields, # true
60
+ :edocs, # true
61
+ :comments, # true
62
+ :major_topics,
63
+ :type,
64
+ :term,
65
+ :topic,
66
+ :title
67
+ end
68
+
69
+ get :get, "/content/{id}.json"
70
+
71
+ end
72
+ end
@@ -0,0 +1,51 @@
1
+ require "test_helper"
2
+
3
+ class TestClient < Test::Unit::TestCase
4
+ VCR.use_cassette("test_title") do
5
+ def test_title
6
+ title = "Open Internet Workshops and Speeches"
7
+ resp = FccContentApi::Content.where(:title => URI.encode(title)).all
8
+ assert_equal resp.first.keys.sort!, ["count", "pages", "itemsPerPage", "currentPage"].sort!
9
+ assert_equal resp[1].keys.sort!, ["nid", "title", "created", "changed", "type", "webUrl", "uri"].sort!
10
+ assert_equal title, resp[1]["title"]
11
+ end
12
+ end
13
+
14
+ VCR.use_cassette("test_all") do
15
+ def test_all
16
+ resp = FccContentApi::Content.all
17
+ assert_equal resp.first.keys.sort!, ["count", "pages", "itemsPerPage", "currentPage"].sort!
18
+ assert_equal resp[1].keys.sort!, ["nid", "title", "created", "changed", "type", "webUrl", "uri"].sort!
19
+ end
20
+ end
21
+
22
+ VCR.use_cassette("test_find") do
23
+ def test_find
24
+ resp = FccContentApi::Content.find 38837
25
+ assert_equal resp.class, Hash
26
+ keys = ["nid", "title", "created", "changed",
27
+ "type", "webUrl", "taxonomy", "body",
28
+ "vid", "field_short_title", "field_short_description",
29
+ "field_author", "field_job_title", "field_edoc_internal_id",
30
+ "field_released_date", "field_published_date",
31
+ "field_adopted_date", "field_comment_date", "field_edoc_id",
32
+ "field_featured_image", "topics", "uri"]
33
+ assert_equal resp.keys.sort!, keys.sort!
34
+ end
35
+ end
36
+
37
+ def test_params
38
+ params = {
39
+ :attribute1 => "value1", # invalid
40
+ :search_string => "searchq" # valid
41
+ }
42
+ req = FccContentApi::Content.where(params).request
43
+ assert_equal req.uri.to_s.split("?")[1], "search_string=searchq"
44
+ end
45
+
46
+ def test_equivalent_queries
47
+ q1 = FccContentApi::Content.where({:search_string => "broadband", :created_afer => "2012-1-1"}).request
48
+ q2 = FccContentApi::Content.where(:search_string => "broadband").where(:created_afer => "2012-1-1").request
49
+ assert_equal q1.uri.to_s, q2.uri.to_s
50
+ end
51
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/unit'
2
+ require 'fcc-content-api'
3
+ require 'vcr'
4
+
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
7
+ #c.stub_with :webmock
8
+ end
@@ -0,0 +1,26 @@
1
+ require "test_helper"
2
+
3
+ class TestQuery < Test::Unit::TestCase
4
+
5
+
6
+ def test_where
7
+ query = FccContentApi::Query.new(FccContentApi::Content)
8
+ query.where(:attribute => "value")
9
+ assert_equal query.criteria[:attribute], "value"
10
+ end
11
+
12
+ def test_stacked_wheres
13
+ query = FccContentApi::Query.new(FccContentApi::Content)
14
+ query.where(:attribute => "value")
15
+ assert_equal query.criteria[:attribute], "value"
16
+ query.where(:second_attribute => "second_value")
17
+ assert_equal query.criteria[:second_attribute], "second_value"
18
+ assert_equal query.criteria[:attribute], "value"
19
+ end
20
+
21
+ def test_request
22
+ query = FccContentApi::Query.new(FccContentApi::Content)
23
+ assert_equal query.request.class, Weary::Request
24
+ end
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fcc-content-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alan deLevie
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-10 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vcr
16
+ requirement: &70341875787080 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70341875787080
25
+ - !ruby/object:Gem::Dependency
26
+ name: webmock
27
+ requirement: &70341875786580 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.8.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70341875786580
36
+ - !ruby/object:Gem::Dependency
37
+ name: weary
38
+ requirement: &70341875786160 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70341875786160
47
+ description: A Ruby wrapper for the FCC's Content API
48
+ email:
49
+ - adelevie@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - README.md
57
+ - Rakefile
58
+ - fcc-content-api.gemspec
59
+ - lib/fcc-content-api.rb
60
+ - lib/fcc-content-api/version.rb
61
+ - test/test_client.rb
62
+ - test/test_helper.rb
63
+ - test/test_query.rb
64
+ homepage: http://github.com/adelevie
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project: fcc-content-api
84
+ rubygems_version: 1.8.10
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: A Ruby wrapper for the FCC's Content API
88
+ test_files:
89
+ - test/test_client.rb
90
+ - test/test_helper.rb
91
+ - test/test_query.rb