Class: API
- Inherits:
-
Object
- Object
- API
- Defined in:
- lib/api.rb
Constant Summary collapse
- @@token =
Store.load_config["api"]
Class Method Summary collapse
- .add_road(params) ⇒ Object
- .delete_road(_id) ⇒ Object
- .log(_id, appId) ⇒ Object
- .road(_id) ⇒ Object
- .roadmaps ⇒ Object
- .roads(_id) ⇒ Object
- .staff(_id) ⇒ Object
- .update_road(_id, message, status) ⇒ Object
-
.updates(log) ⇒ Object
we’ll handle updates by parallel processing them with typhoeus.
Class Method Details
.add_road(params) ⇒ Object
37 38 39 40 |
# File 'lib/api.rb', line 37 def self.add_road(params) url = "https://api.interstateapp.com/v1/road/new.json?oauth_token=#{@@token}" return JSON.parse(Nestful.post url, :params => params)["response"] end |
.delete_road(_id) ⇒ Object
42 43 44 45 |
# File 'lib/api.rb', line 42 def self.delete_road(_id) url = "https://api.interstateapp.com/v1/road/delete/id/#{_id}.json?oauth_token=#{@@token}" return JSON.parse(Nestful.get url)["response"] end |
.log(_id, appId) ⇒ Object
47 48 49 50 |
# File 'lib/api.rb', line 47 def self.log(_id, appId) url = "https://api.interstateapp.com/v1/activity/list/id/#{appId}/limit/10.json?oauth_token=#{@@token}" return JSON.parse(Nestful.post url, :params => { "filter" => "roadmap-#{_id}" } )["response"] end |
.road(_id) ⇒ Object
18 19 20 21 |
# File 'lib/api.rb', line 18 def self.road(_id) url = "https://api.interstateapp.com/v1/road/#{_id}.json?oauth_token=#{@@token}" return (Nestful.json_get url)["response"] end |
.roadmaps ⇒ Object
8 9 10 11 |
# File 'lib/api.rb', line 8 def self.roadmaps() url = "https://api.interstateapp.com/v1/roadmap/listAll.json?oauth_token=#{@@token}" return (Nestful.json_get url)["response"] end |
.roads(_id) ⇒ Object
13 14 15 16 |
# File 'lib/api.rb', line 13 def self.roads(_id) url = "https://api.interstateapp.com/v1/roadmap/roads/id/#{_id}.json?oauth_token=#{@@token}" return (Nestful.json_get url)["response"] end |
.staff(_id) ⇒ Object
32 33 34 35 |
# File 'lib/api.rb', line 32 def self.staff(_id) url = "https://api.interstateapp.com/v1/roadmap/staff/id/#{_id}.json?oauth_token=#{@@token}" return (Nestful.json_get url)["response"] end |
.update_road(_id, message, status) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/api.rb', line 23 def self.update_road(_id, , status) params = { "update" => "#{}" } if status != nil params["status"] = status end url = "https://api.interstateapp.com/v1/road/update/id/#{_id}.json?oauth_token=#{@@token}" return JSON.parse(Nestful.post url, :params => params)["response"] end |
.updates(log) ⇒ Object
we’ll handle updates by parallel processing them with typhoeus
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/api.rb', line 52 def self.updates(log) # we'll handle updates by parallel processing them with typhoeus hydra = Typhoeus::Hydra.new(:max_concurrency => 50) updates = [] log.each do |entry| if entry["type"] == "github" begin info = entry["comments"][0] updates << { "update" => info["comment"], "time" => info["time"], "staffId" => info["staffId"], "type" => "GitHub Commit" } rescue end elsif entry["type"] == "road_update" r = Typhoeus::Request.new("https://api.interstateapp.com/v1/update/get/id/#{entry["updateId"]}.json?oauth_token=#{@@token}") r.on_complete do |response| update = JSON.parse(response.body)["response"] if update.class != NilClass update["type"] = "Road Update" updates << update end end hydra.queue r elsif entry["type"] == "road" r = Typhoeus::Request.new("https://api.interstateapp.com/v1/road/#{entry["roadId"]}.json?oauth_token=#{@@token}") r.on_complete do |response| road = JSON.parse(response.body)["response"] if road.class != NilClass updates << { "update" => "New Road: #{road["title"]}", "time" => entry["time"], "staffId" => entry["staffId"], "type" => "New Road" } end end hydra.queue r end hydra.run end return updates end |