Class: Groundcrew

Inherits:
Struct
  • Object
show all
Defined in:
lib/groundcrew.rb

Defined Under Namespace

Classes: Hashwrapper

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key

Returns:

  • (Object)

    the current value of api_key



4
5
6
# File 'lib/groundcrew.rb', line 4

def api_key
  @api_key
end

#squad_idObject

Returns the value of attribute squad_id

Returns:

  • (Object)

    the current value of squad_id



4
5
6
# File 'lib/groundcrew.rb', line 4

def squad_id
  @squad_id
end

Class Method Details

.api(squad_id, api_key, &blk) ⇒ Object

create a new instance and run a block inside of it to make multiple authenticated calls



8
9
10
# File 'lib/groundcrew.rb', line 8

def self.api(squad_id, api_key, &blk)
  new(squad_id, api_key).instance_eval(&blk)
end

Instance Method Details

#add_people(folx) ⇒ Object



19
20
21
# File 'lib/groundcrew.rb', line 19

def add_people folx
  post "/people/import.json", :json => folx.to_json
end

#add_person(name, params = {}) ⇒ Object



23
24
25
26
# File 'lib/groundcrew.rb', line 23

def add_person name, params = {}
  params.merge! :name => name
  add_people [params]
end

#exec(loc, script, params = {}) ⇒ Object

def invite params; post ‘people/invite’, params; end



14
15
16
17
# File 'lib/groundcrew.rb', line 14

def exec loc, script, params = {}
  params.merge! :script => script, :loc => loc
  http :post, "/exec", params
end

#stream_people(params = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/groundcrew.rb', line 28

def stream_people params = {}
  since = nil
  params[:query] = "s#{squad_id}"
  loop do
    params[:since] = since if since
    http(:get, "stream.js", params).each_line do |line|
      next unless line =~ /^(item|at)\((.*)\);$/
      case $1
      when 'at'; since = $2
      else
        item_args = Yajl::Parser.parse("[#{$2}]")
        next unless item_args[1] =~ /^Person__|^p/
        vals = item_args.pop
        vals.merge! Hash[%w{city_id id name thumb_url lat lng tags latch comm req}.zip(item_args)]
        yield Hashwrapper.new vals
      end
    end
    sleep 10
  end
end