Class: Socrata

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/socrata/data.rb,
lib/socrata.rb

Overview

Copyright © 2010 Socrata.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Direct Known Subclasses

Data

Defined Under Namespace

Classes: Data, User, View

Constant Summary collapse

DEFAULT_CONFIG =
{
  :base_uri => "http://www.socrata.com/api"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Socrata

Returns a new instance of Socrata.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/socrata.rb', line 41

def initialize(params = {})
  @config = DEFAULT_CONFIG.merge(Util.symbolize_keys(params))
  @logger = @config[:logger] || Logger.new(STDOUT)
  @batching = false
  @batch_queue = []

  if @config[:username]
    self.class.basic_auth(@config[:username],
                          @config[:password])
  else
    self.class.default_options[:basic_auth] = nil
  end

  self.class.base_uri @config[:base_uri]

  # Keep around a self reference because we need it
  @party = self.class
end

Instance Attribute Details

#batchingObject (readonly)

Returns the value of attribute batching.



32
33
34
# File 'lib/socrata.rb', line 32

def batching
  @batching
end

#configObject (readonly)

Returns the value of attribute config.



32
33
34
# File 'lib/socrata.rb', line 32

def config
  @config
end

#errorObject (readonly)

Returns the value of attribute error.



32
33
34
# File 'lib/socrata.rb', line 32

def error
  @error
end

Instance Method Details

#batch_requestObject

Wrap a proc for a batch request



69
70
71
72
73
74
75
# File 'lib/socrata.rb', line 69

def batch_request()
  @batching = true
  @batch_queue = []
  yield
  @batching = false
  flush_batch_queue();
end

#user(uid_or_login) ⇒ Object



60
61
62
# File 'lib/socrata.rb', line 60

def user()
  return User.new(get_request("/users/#{}.json"), @party)
end

#view(uid) ⇒ Object



64
65
66
# File 'lib/socrata.rb', line 64

def view(uid)
  return View.new(get_request("/views/#{uid}.json"), @party)
end