Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

port Bugly service

  • Loading branch information...
commit cd3ca9145af27f980ebd04c7e914075c8a0cb377 1 parent fd22aee
@technoweenie technoweenie authored
Showing with 46 additions and 9 deletions.
  1. +17 −9 services/bugly.rb
  2. +29 −0 test/bugly_test.rb
View
26 services/bugly.rb
@@ -1,10 +1,18 @@
-service :bugly do |data, payload|
- account = "http://#{data['account_name']}.bug.ly"
- query_string = "?service=github&project_id=#{data['project_id']}"
- url = URI.parse("#{account}/changesets.json#{query_string}")
- req = Net::HTTP::Post.new(url.request_uri)
- req.body = JSON.generate(payload)
- req.initialize_http_header({"X-BuglyToken" => data['token']})
- req.set_content_type('application/json')
- Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
+class Service::Bugly < Service
+ self.hook_name = :bugly
+
+ def receive_push
+ http_post "http://#{data['account_name']}.bug.ly/changesets.json",
+ JSON.generate(payload),
+ 'X-BuglyToken' => data['token'],
+ 'Content-Type' => 'application/json'
+ return
+ query_string = "?service=github&project_id=#{data['project_id']}"
+ url = URI.parse("#{account}/changesets.json#{query_string}")
+ req = Net::HTTP::Post.new(url.request_uri)
+ req.body = JSON.generate(payload)
+ req.initialize_http_header({"X-BuglyToken" => data['token']})
+ req.set_content_type('application/json')
+ Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
+ end
end
View
29 test/bugly_test.rb
@@ -0,0 +1,29 @@
+require File.expand_path('../helper', __FILE__)
+
+class BuglyTest < Service::TestCase
+ def setup
+ @stubs = Faraday::Adapter::Test::Stubs.new
+ end
+
+ def test_push
+ svc = service :push, {'token' => 'abc'}, {'a' => 1}
+
+ @stubs.post "/changesets.json" do |env|
+ assert_equal %({"a":1}), env[:body]
+ assert_equal 'abc', env[:request_headers]['X-BuglyToken']
+ assert_equal 'application/json', env[:request_headers]['Content-Type']
+ [200, {}, '']
+ end
+
+ svc.receive_push
+
+ @stubs.verify_stubbed_calls
+ end
+
+ def service(*args)
+ super Service::Bugly, *args
+ end
+end
+
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.