Skip to content

Commit

Permalink
port Bugly service
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Jun 6, 2011
1 parent fd22aee commit cd3ca91
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
26 changes: 17 additions & 9 deletions services/bugly.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,10 +1,18 @@
service :bugly do |data, payload| class Service::Bugly < Service
account = "http://#{data['account_name']}.bug.ly" self.hook_name = :bugly
query_string = "?service=github&project_id=#{data['project_id']}"
url = URI.parse("#{account}/changesets.json#{query_string}") def receive_push
req = Net::HTTP::Post.new(url.request_uri) http_post "http://#{data['account_name']}.bug.ly/changesets.json",
req.body = JSON.generate(payload) JSON.generate(payload),
req.initialize_http_header({"X-BuglyToken" => data['token']}) 'X-BuglyToken' => data['token'],
req.set_content_type('application/json') 'Content-Type' => 'application/json'
Net::HTTP.new(url.host, url.port).start {|http| http.request(req) } 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 end
29 changes: 29 additions & 0 deletions test/bugly_test.rb
Original file line number Original file line Diff line number Diff line change
@@ -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



0 comments on commit cd3ca91

Please sign in to comment.