webhook-payload 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -67,6 +67,9 @@ You can load that into an object with:
67
67
 
68
68
  ``` ruby
69
69
  payload = Webhook::Payload.new(payload_data)
70
+
71
+ # Or if you want to load it directly from a json string
72
+ payload = Webhook::Payload.from_json(payload_data_json)
70
73
  ```
71
74
 
72
75
  Then you can access the data via methods rather than through hash keys. It also does conversion of timestamps to `Time`, integer booleans to `true` or `false`, urls to `URI`, and file to `Pathname`.
@@ -1,6 +1,7 @@
1
1
  require 'virtus'
2
2
  require 'pathname'
3
3
  require 'uri'
4
+ require 'multi_json'
4
5
 
5
6
  module Virtus
6
7
  class Coercion
@@ -20,6 +21,10 @@ module Webhook
20
21
  class Payload
21
22
  include Virtus
22
23
 
24
+ def self.from_json(json)
25
+ new(MultiJson.load(json))
26
+ end
27
+
23
28
  module User
24
29
  include Virtus
25
30
 
@@ -1,5 +1,5 @@
1
1
  module Webhook
2
2
  class Payload
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -1,98 +1,111 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Webhook::Payload do
4
- let(:payload){Webhook::Payload.new(payload_data)}
5
- subject{payload}
4
+ describe ".from_json" do
5
+ let(:payload_data){{'cool' => 'neat'}}
6
+ let(:json){'{"cool": "neat"}'}
6
7
 
7
- its(:before){should == "5aef35982fb2d34e9d9d4502f6ede1072793222d"}
8
- its(:after){should == "de8251ff97ee194a289832576287d6f8ad74e3d0"}
9
- its(:ref){should == "refs/heads/master"}
8
+ it "should create a new Webhook::Payload after converting the json passed into ruby literals" do
9
+ Webhook::Payload.should_receive(:new).with(payload_data)
10
10
 
11
- it "should have two commits" do
12
- subject.commits.size.should == 2
11
+ Webhook::Payload.from_json(json)
12
+ end
13
13
  end
14
14
 
15
- describe "#respository" do
16
- let(:repository){payload.repository}
17
- subject{repository}
15
+ describe "with sample payload data" do
16
+ let(:payload){Webhook::Payload.new(payload_data)}
17
+ subject{payload}
18
+
19
+ its(:before){should == "5aef35982fb2d34e9d9d4502f6ede1072793222d"}
20
+ its(:after){should == "de8251ff97ee194a289832576287d6f8ad74e3d0"}
21
+ its(:ref){should == "refs/heads/master"}
22
+
23
+ it "should have two commits" do
24
+ subject.commits.size.should == 2
25
+ end
26
+
27
+ describe "#respository" do
28
+ let(:repository){payload.repository}
29
+ subject{repository}
18
30
 
19
- its(:url){should == URI.parse("http://github.com/defunkt/github")}
20
- its(:name){should == "github"}
21
- its(:pledgie){should be_nil}
22
- its(:homepage){should be_nil}
23
- its(:description){should == "You're lookin' at it."}
24
- its(:watchers){should == 5}
25
- its(:forks){should == 2}
26
- its(:private){should == true}
31
+ its(:url){should == URI.parse("http://github.com/defunkt/github")}
32
+ its(:name){should == "github"}
33
+ its(:pledgie){should be_nil}
34
+ its(:homepage){should be_nil}
35
+ its(:description){should == "You're lookin' at it."}
36
+ its(:watchers){should == 5}
37
+ its(:forks){should == 2}
38
+ its(:private){should == true}
27
39
 
28
- describe "#owner" do
29
- subject{repository.owner}
40
+ describe "#owner" do
41
+ subject{repository.owner}
30
42
 
31
- its(:email){should == "chris@ozmm.org"}
32
- its(:name){should == "defunkt"}
43
+ its(:email){should == "chris@ozmm.org"}
44
+ its(:name){should == "defunkt"}
45
+ end
33
46
  end
34
- end
35
47
 
36
- describe "a commit" do
37
- let(:commit){payload.commits.first}
38
- subject{commit}
48
+ describe "a commit" do
49
+ let(:commit){payload.commits.first}
50
+ subject{commit}
39
51
 
40
- its(:id){should == "41a212ee83ca127e3c8cf465891ab7216a705f59"}
41
- its(:url){should == URI.parse("http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59")}
42
- its(:message){should == "okay i give in"}
43
- its(:timestamp){should == Time.parse("2008-02-15T14:57:17-08:00")}
44
- its(:added){should == [Pathname.new("filepath.rb")]}
45
- its(:removed){should == []}
46
- its(:modified){should == []}
52
+ its(:id){should == "41a212ee83ca127e3c8cf465891ab7216a705f59"}
53
+ its(:url){should == URI.parse("http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59")}
54
+ its(:message){should == "okay i give in"}
55
+ its(:timestamp){should == Time.parse("2008-02-15T14:57:17-08:00")}
56
+ its(:added){should == [Pathname.new("filepath.rb")]}
57
+ its(:removed){should == []}
58
+ its(:modified){should == []}
47
59
 
48
- describe "#author" do
49
- subject{commit.author}
60
+ describe "#author" do
61
+ subject{commit.author}
50
62
 
51
- its(:email){should == "chris@ozmm.org"}
52
- its(:name){should == "Chris Wanstrath"}
63
+ its(:email){should == "chris@ozmm.org"}
64
+ its(:name){should == "Chris Wanstrath"}
65
+ end
53
66
  end
54
- end
55
67
 
56
- let(:payload_data) do
57
- {
58
- "before" => "5aef35982fb2d34e9d9d4502f6ede1072793222d",
59
- "repository" => {
60
- "url" => "http://github.com/defunkt/github",
61
- "name" => "github",
62
- "description" => "You're lookin' at it.",
63
- "watchers" => 5,
64
- "forks" => 2,
65
- "private" => 1,
66
- "owner" => {
67
- "email" => "chris@ozmm.org",
68
- "name" => "defunkt"
69
- }
70
- },
71
- "commits" => [
72
- {
73
- "id" => "41a212ee83ca127e3c8cf465891ab7216a705f59",
74
- "url" => "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
75
- "author" => {
68
+ let(:payload_data) do
69
+ {
70
+ "before" => "5aef35982fb2d34e9d9d4502f6ede1072793222d",
71
+ "repository" => {
72
+ "url" => "http://github.com/defunkt/github",
73
+ "name" => "github",
74
+ "description" => "You're lookin' at it.",
75
+ "watchers" => 5,
76
+ "forks" => 2,
77
+ "private" => 1,
78
+ "owner" => {
76
79
  "email" => "chris@ozmm.org",
77
- "name" => "Chris Wanstrath"
78
- },
79
- "message" => "okay i give in",
80
- "timestamp" => "2008-02-15T14:57:17-08:00",
81
- "added" => ["filepath.rb"]
80
+ "name" => "defunkt"
81
+ }
82
82
  },
83
- {
84
- "id" => "de8251ff97ee194a289832576287d6f8ad74e3d0",
85
- "url" => "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
86
- "author" => {
87
- "email" => "chris@ozmm.org",
88
- "name" => "Chris Wanstrath"
83
+ "commits" => [
84
+ {
85
+ "id" => "41a212ee83ca127e3c8cf465891ab7216a705f59",
86
+ "url" => "http://github.com/defunkt/github/commit/41a212ee83ca127e3c8cf465891ab7216a705f59",
87
+ "author" => {
88
+ "email" => "chris@ozmm.org",
89
+ "name" => "Chris Wanstrath"
90
+ },
91
+ "message" => "okay i give in",
92
+ "timestamp" => "2008-02-15T14:57:17-08:00",
93
+ "added" => ["filepath.rb"]
89
94
  },
90
- "message" => "update pricing a tad",
91
- "timestamp" => "2008-02-15T14:36:34-08:00"
92
- }
93
- ],
94
- "after" => "de8251ff97ee194a289832576287d6f8ad74e3d0",
95
- "ref" => "refs/heads/master"
96
- }
95
+ {
96
+ "id" => "de8251ff97ee194a289832576287d6f8ad74e3d0",
97
+ "url" => "http://github.com/defunkt/github/commit/de8251ff97ee194a289832576287d6f8ad74e3d0",
98
+ "author" => {
99
+ "email" => "chris@ozmm.org",
100
+ "name" => "Chris Wanstrath"
101
+ },
102
+ "message" => "update pricing a tad",
103
+ "timestamp" => "2008-02-15T14:36:34-08:00"
104
+ }
105
+ ],
106
+ "after" => "de8251ff97ee194a289832576287d6f8ad74e3d0",
107
+ "ref" => "refs/heads/master"
108
+ }
109
+ end
97
110
  end
98
111
  end
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "rspec"
23
23
  s.add_development_dependency "rake"
24
24
  s.add_runtime_dependency "virtus"
25
+ s.add_runtime_dependency "multi_json"
25
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webhook-payload
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-03 00:00:00.000000000 Z
12
+ date: 2012-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70231675027840 !ruby/object:Gem::Requirement
16
+ requirement: &70203489228800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70231675027840
24
+ version_requirements: *70203489228800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70231675027380 !ruby/object:Gem::Requirement
27
+ requirement: &70203489228280 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70231675027380
35
+ version_requirements: *70203489228280
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: virtus
38
- requirement: &70231675026940 !ruby/object:Gem::Requirement
38
+ requirement: &70203489227740 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,18 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70231675026940
46
+ version_requirements: *70203489227740
47
+ - !ruby/object:Gem::Dependency
48
+ name: multi_json
49
+ requirement: &70203489227160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70203489227160
47
58
  description: This gem is a convenience wrapper for Github's webhook payload (https://help.github.com/articles/post-receive-hooks)
48
59
  that is triggered from a post receive hook. Feed it a hash of data and it will parse
49
60
  it into an object that you can use. It also provides conversions from basic data