windy 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +5 -1
  2. data/lib/windy.rb +27 -2
  3. metadata +7 -9
data/README.md CHANGED
@@ -19,6 +19,10 @@ First off, install the Windy gem, and fire up your irb console.
19
19
  >> require 'rubygems'
20
20
  >> require 'windy'
21
21
 
22
+ Note: The Socrata API is [rate-limited](http://dev.socrata.com/authentication) by default. If you would like to increase your quota, [register for an app token](http://dev.socrata.com/register) and pass it to Windy as follows:
23
+
24
+ >> Windy.app_token = "insert_your_app_token_here"
25
+
22
26
  ### Views
23
27
 
24
28
  Views are at the heart of each dataset. In a nutshell, every dataset has at least one view, the original view. Users of the Data Portal are allowed to create customized views, however for the sake of this walk-through, we'll only be discussing the original view.
@@ -28,7 +32,7 @@ To get an Array of all views:
28
32
  >> all_views = Windy.views
29
33
  >> all_views.count
30
34
  => 537
31
- >> first_view = views.first
35
+ >> first_view = all_views.first
32
36
 
33
37
  If you know which view you'd like to work with, you can access it directly by the View ID. In the following example, we found the the View's ID by looking at the end of the [Towed Vehicle's dataset URL](http://data.cityofchicago.org/Government/Towed-Vehicles/ygr5-vcbg).
34
38
 
@@ -2,7 +2,19 @@ require 'faraday'
2
2
  require 'multi_json'
3
3
 
4
4
  module Windy
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
+
7
+ class << self
8
+ attr_accessor :app_token, :debug
9
+ end
10
+
11
+ class SocrataAppTokenMiddleware < Faraday::Middleware
12
+ def call(env)
13
+ raise "You must specify an app token" if !Windy.app_token
14
+ env[:request_headers]["X-App-Token"] = Windy.app_token
15
+ @app.call env
16
+ end
17
+ end
6
18
 
7
19
  class Base
8
20
  def self.root
@@ -12,7 +24,17 @@ module Windy
12
24
  attr_reader :connection
13
25
 
14
26
  def initialize
15
- @connection = Faraday.new(:url => self.class.root)
27
+ @connection = Faraday.new(:url => self.class.root) do |builder|
28
+ builder.use SocrataAppTokenMiddleware
29
+ builder.request :json
30
+
31
+ # Enable logger output with Windy.debug = true
32
+ if Windy.debug
33
+ builder.response :logger
34
+ end
35
+
36
+ builder.adapter :net_http
37
+ end
16
38
  end
17
39
 
18
40
  def body
@@ -26,6 +48,9 @@ module Windy
26
48
  end
27
49
 
28
50
  def json
51
+ # For some reason ruby 1.9.x seems to be trying to parse the
52
+ # API JSON output as ASCII instead of UTF-8
53
+ body.force_encoding("UTF-8") unless body.nil?
29
54
  @json ||= MultiJson.decode(body)
30
55
  end
31
56
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: windy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-07-16 00:00:00.000000000 -05:00
14
- default_executable:
13
+ date: 2011-10-01 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: faraday
18
- requirement: &70118986024880 !ruby/object:Gem::Requirement
17
+ requirement: &70259918929340 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
21
20
  - - ~>
@@ -23,10 +22,10 @@ dependencies:
23
22
  version: '0.7'
24
23
  type: :runtime
25
24
  prerelease: false
26
- version_requirements: *70118986024880
25
+ version_requirements: *70259918929340
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: multi_json
29
- requirement: &70118986023900 !ruby/object:Gem::Requirement
28
+ requirement: &70259918928720 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
32
31
  - - ~>
@@ -34,7 +33,7 @@ dependencies:
34
33
  version: '1.0'
35
34
  type: :runtime
36
35
  prerelease: false
37
- version_requirements: *70118986023900
36
+ version_requirements: *70259918928720
38
37
  description: Windy is a Ruby module that allows you to easily interact with the City
39
38
  of Chicago's Data Portal.
40
39
  email:
@@ -46,7 +45,6 @@ extra_rdoc_files: []
46
45
  files:
47
46
  - README.md
48
47
  - lib/windy.rb
49
- has_rdoc: true
50
48
  homepage: http://github.com/chicago/windy
51
49
  licenses: []
52
50
  post_install_message:
@@ -67,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
65
  version: '0'
68
66
  requirements: []
69
67
  rubyforge_project:
70
- rubygems_version: 1.6.2
68
+ rubygems_version: 1.8.10
71
69
  signing_key:
72
70
  specification_version: 3
73
71
  summary: Ruby interface to the City of Chicago's Data Portal API