ruby-box 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTI2NDAyOTY0NGNlZmE0MjdjMGI0MTEyZmI0MjgwYmYyODY0YzFhNg==
4
+ YzdhOWY3MTVjMjU3ZDA1YzIwYmUyNGViNzBmNzM2NTNmM2I4MmI5MQ==
5
5
  data.tar.gz: !binary |-
6
- MDExZTg4NTcyZjYyNWUyMDk0MDM1ZDk4NzQ2MmVhMDZkNDBlYWQ5Yg==
6
+ YjkzMGYyMDIzMTdhYjNlOGRlYWQxMjAxODI2YjM5YjY5ZjczZTBhYQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MDYwZTM1ZjYwNWNlY2JjMDc2MWEwZDlhNzBlY2MwOGFlZThhNmE2MmNhMTg1
10
- N2M4YmY0YTVmYjZhMTk1ZDNiMDNlMjIyZGNiM2VjMDBlYzBmZDJiYTBhMzAw
11
- MjcxMjljYmUzY2FmNzQwNWY1ZTc5YTBjNzE4ZTk3N2U2YzgyNmM=
9
+ Mjg1NjViNGRlNWZhYjgxNzY2ZTcxZGU2MDQ3YjFmYzQ3OTBjMjY5NTkzZDcz
10
+ YWFmNzYzMjViZWQxNmYwMWQzNTM5NDliYjUxNTEyMjYwM2Y1YmJmMjIyMGVh
11
+ M2Y2YWE2ZTAxZGVlY2JiNzg2Y2EwNmQ4MTY4OTY3OWY4OWZiMWQ=
12
12
  data.tar.gz: !binary |-
13
- YjA2M2NkY2Y4Nzc3Yzk3NTRlMjJjZGU3YTVlZmRjMDA0NjFlMWFmNDQ1ZDc3
14
- ZDk0OWJlYjZjYTVkZjZmNTIwNDZlMzU2ZTAxNzY4OGQ5M2YwMWU2NTQwOTJm
15
- ODExOGJiYWJiYjhjNWYyMGJjZTAyMjJmMzZhOGFkMzY4N2FlOTY=
13
+ NWI0MjIyMDkyZTdjNjViY2NjMjRhNTMxNmQ3MzQxZGJhZDI4ZWJlNjA2NTY1
14
+ ODdiNWQwOGJkZTBiYTY1YjQyOTBiMTdlNzQwY2M2ZTg4NzIxNmEzYmE3NTc1
15
+ N2ViZjRhZGM1YmNkMzE3ZGU4ZDdmMDE1MmY3OTllMTBlYTljMmI=
@@ -138,6 +138,22 @@ items.each do |item|
138
138
  end
139
139
  ```
140
140
 
141
+ Events
142
+ ======
143
+
144
+ You can use RubyBox's event_response method to return an EventResponse that can be used to process any incoming events.
145
+
146
+ ```ruby
147
+ eresp = client.event_response
148
+ eresp.chunk_size
149
+ eresp.next_stream_position
150
+ eresp.events.each do |ev|
151
+ p "type=#{ev.event_id} type=#{ev.event_type} user=#{ev.created_by.name}"
152
+ end
153
+ ```
154
+
155
+
156
+
141
157
  Contributors
142
158
  ------------
143
159
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -8,6 +8,8 @@ require 'ruby-box/user'
8
8
  require 'ruby-box/comment'
9
9
  require 'ruby-box/discussion'
10
10
  require 'ruby-box/exceptions'
11
+ require 'ruby-box/event_response'
12
+ require 'ruby-box/event'
11
13
 
12
14
  module RubyBox
13
15
  API_URL = 'https://api.box.com/2.0'
@@ -89,6 +89,13 @@ module RubyBox
89
89
  path.split('/')
90
90
  end
91
91
 
92
+ def event_response(stream_position=0, stream_type=:all, limit=100)
93
+ q = fmt_events_args stream_position, stream_type, limit
94
+ url = "#{RubyBox::API_URL}/events?#{q}"
95
+ resp = @session.get( url )
96
+ EventResponse.new(@session, resp)
97
+ end
98
+
92
99
  private
93
100
 
94
101
  def folder_from_split_path(path)
@@ -99,6 +106,13 @@ module RubyBox
99
106
  end
100
107
  folder
101
108
  end
109
+
110
+ def fmt_events_args(stream_position, stream_type, limit)
111
+ stream_position = stream_position.kind_of?(Numeric) ? stream_position : 0
112
+ stream_type = [:all, :changes, :sync].include?(stream_type) ? stream_type : :all
113
+ limit = limit.kind_of?(Fixnum) ? limit : 100
114
+ "stream_position=#{stream_position}&stream_type=#{stream_type}&limit=#{limit}"
115
+ end
102
116
 
103
117
  end
104
- end
118
+ end
@@ -0,0 +1,11 @@
1
+ module RubyBox
2
+ class Event < Item
3
+
4
+ private
5
+
6
+ def has_mini_format?
7
+ false
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module RubyBox
2
+ class EventResponse < Item
3
+
4
+ def events
5
+ @events ||= entries.collect {|ev|
6
+ RubyBox::Event.new(@session, ev)
7
+ }
8
+ end
9
+
10
+ private
11
+
12
+ def resource_name
13
+ 'events'
14
+ end
15
+
16
+ def has_mini_format?
17
+ false
18
+ end
19
+
20
+ end
21
+ end
@@ -59,7 +59,7 @@ module RubyBox
59
59
  @raw_item[key] = args[0] if setter and update_fields.include?(key)
60
60
 
61
61
  # we may have a mini version of the object loaded, fix this.
62
- reload_meta if @raw_item[key].nil?
62
+ reload_meta if @raw_item[key].nil? and has_mini_format?
63
63
 
64
64
  if @raw_item[key].kind_of?(Hash)
65
65
  return RubyBox::Item.factory(@session, @raw_item[key])
@@ -81,13 +81,17 @@ module RubyBox
81
81
  when 'comment'
82
82
  return RubyBox::Comment.new(session, entry)
83
83
  when 'user'
84
- return RubyBox::User.new(session, entry)
84
+ return RubyBox::User.new(session, entry)
85
85
  when 'discussion'
86
86
  return RubyBox::Discussion.new(session, entry)
87
87
  end
88
88
  entry
89
89
  end
90
90
 
91
+ def has_mini_format?
92
+ true
93
+ end
94
+
91
95
  private
92
96
 
93
97
  def many(key)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ruby-box"
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Attachments.me"]
12
- s.date = "2013-04-19"
12
+ s.date = "2013-04-23"
13
13
  s.description = "ruby gem for box.com 2.0 api"
14
14
  s.email = "ben@attachments.me"
15
15
  s.extra_rdoc_files = [
@@ -28,6 +28,8 @@ Gem::Specification.new do |s|
28
28
  "lib/ruby-box/client.rb",
29
29
  "lib/ruby-box/comment.rb",
30
30
  "lib/ruby-box/discussion.rb",
31
+ "lib/ruby-box/event.rb",
32
+ "lib/ruby-box/event_response.rb",
31
33
  "lib/ruby-box/exceptions.rb",
32
34
  "lib/ruby-box/file.rb",
33
35
  "lib/ruby-box/folder.rb",
@@ -36,7 +38,9 @@ Gem::Specification.new do |s|
36
38
  "lib/ruby-box/user.rb",
37
39
  "ruby-box.gemspec",
38
40
  "spec/client_spec.rb",
41
+ "spec/event_spec.rb",
39
42
  "spec/file_spec.rb",
43
+ "spec/fixtures/events.json",
40
44
  "spec/fixtures/遠志教授.jpg",
41
45
  "spec/folder_spec.rb",
42
46
  "spec/helper/account.example",
@@ -0,0 +1,65 @@
1
+ #encoding: UTF-8
2
+
3
+ require 'ruby-box'
4
+ require 'webmock/rspec'
5
+
6
+ describe RubyBox::EventResponse do
7
+ before do
8
+ @session = RubyBox::Session.new
9
+ @client = RubyBox::Client.new(@session)
10
+ @events_json = File.read 'spec/fixtures/events.json'
11
+ @events = JSON.load @events_json
12
+ stub_request(:get, /#{RubyBox::API_URL}\/events.*/).to_return(body: @events_json, :status => 200)
13
+ end
14
+
15
+ it 'returns an EventResponse with a chunk_size and next_stream_position' do
16
+ eresp = @client.event_response
17
+ eresp.instance_of?(RubyBox::EventResponse).should be_true
18
+ eresp.events.instance_of?(Array).should be_true
19
+ eresp.chunk_size.should eq(@events['chunk_size'])
20
+ eresp.events.length.should eq(@events['chunk_size'])
21
+ eresp.next_stream_position.should eq(@events['next_stream_position'])
22
+ end
23
+
24
+ it "should not try to reload_meta since has_mini_format? is false" do
25
+ # request is called once when reload_meta is automatically executed.
26
+ RubyBox::Session.any_instance.should_not_receive(:request)
27
+ response = @client.event_response
28
+ event = response.events.first
29
+ event.missing_key
30
+ end
31
+
32
+ describe '#event_response' do
33
+ before do
34
+ @response = @client.event_response
35
+ @event = @response.events.first
36
+ end
37
+
38
+ it 'should return Event objects in the event response' do
39
+ @event.instance_of?(RubyBox::Event).should be_true
40
+ end
41
+
42
+ it 'should return an #event_id' do
43
+ @event.event_id.should eq(@events['entries'][0]['event_id'])
44
+ end
45
+
46
+ it 'should return a User for #created_by' do
47
+ @event.created_by.instance_of?(RubyBox::User).should be_true
48
+ end
49
+
50
+ it 'should return an #event_type' do
51
+ @event.event_type.should eq(@events['entries'][0]['event_type'])
52
+ end
53
+
54
+ it 'should return a #session_id' do
55
+ @event.session_id.should eq(@events['entries'][0]['session_id'])
56
+ end
57
+
58
+ it 'should return an instantiated #source' do
59
+ @event.source.instance_of?(RubyBox::Folder).should be_true
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
@@ -0,0 +1,161 @@
1
+ {
2
+ "chunk_size": 3,
3
+ "next_stream_position": 1366038336000,
4
+ "entries": [
5
+ {
6
+ "type": "event",
7
+ "event_id": "dd4cba8afb2acb3cc0ecc43c81e565e78886494b",
8
+ "created_by": {
9
+ "type": "user",
10
+ "id": "000000000",
11
+ "name": "Example User",
12
+ "login": "test@example.com"
13
+ },
14
+ "created_at": "2013-04-12T13:53:52-07:00",
15
+ "recorded_at": "2013-04-12T13:53:52-07:00",
16
+ "event_type": "ITEM_CREATE",
17
+ "session_id": "d223c5ba4f4eb1d0b4fb55a",
18
+ "source": {
19
+ "type": "folder",
20
+ "id": "805142927",
21
+ "sequence_id": "0",
22
+ "etag": "0",
23
+ "name": "Test Folder",
24
+ "created_at": "2013-04-12T13:53:52-07:00",
25
+ "modified_at": "2013-04-12T13:53:52-07:00",
26
+ "description": "",
27
+ "size": 0,
28
+ "path_collection": {
29
+ "total_count": 1,
30
+ "entries": [
31
+ {
32
+ "type": "folder",
33
+ "id": "0",
34
+ "sequence_id": null,
35
+ "etag": null,
36
+ "name": "All Files"
37
+ }
38
+ ]
39
+ },
40
+ "created_by": {
41
+ "type": "user",
42
+ "id": "000000000",
43
+ "name": "Example User",
44
+ "login": "test@example.com"
45
+ },
46
+ "modified_by": {
47
+ "type": "user",
48
+ "id": "000000000",
49
+ "name": "Example User",
50
+ "login": "test@example.com"
51
+ },
52
+ "trashed_at": null,
53
+ "purged_at": null,
54
+ "content_created_at": "2013-04-12T13:53:52-07:00",
55
+ "content_modified_at": "2013-04-12T13:53:52-07:00",
56
+ "owned_by": {
57
+ "type": "user",
58
+ "id": "000000000",
59
+ "name": "Example User",
60
+ "login": "test@example.com"
61
+ },
62
+ "shared_link": null,
63
+ "folder_upload_email": null,
64
+ "parent": {
65
+ "type": "folder",
66
+ "id": "0",
67
+ "sequence_id": null,
68
+ "etag": null,
69
+ "name": "All Files"
70
+ },
71
+ "item_status": "active",
72
+ "synced": false
73
+ }
74
+ },
75
+ {
76
+ "type": "event",
77
+ "event_id": "dd4cba8afb2acb3cc0ecc43c81e565e78886494c",
78
+ "created_by": {
79
+ "type": "user",
80
+ "id": "000000000",
81
+ "name": "Example User",
82
+ "login": "test@example.com"
83
+ },
84
+ "created_at": "2013-04-12T13:54:25-07:00",
85
+ "recorded_at": "2013-04-12T13:54:26-07:00",
86
+ "event_type": "ITEM_RENAME",
87
+ "session_id": "d223c5ba4f4eb1d0b4fb55a",
88
+ "source": {
89
+ "type": "folder",
90
+ "id": "805142927",
91
+ "sequence_id": "1",
92
+ "etag": "1",
93
+ "name": "Test Folder",
94
+ "created_at": "2013-04-12T13:53:52-07:00",
95
+ "modified_at": "2013-04-12T13:54:25-07:00",
96
+ "description": "Project: Test",
97
+ "size": 0,
98
+ "path_collection": {
99
+ "total_count": 1,
100
+ "entries": [
101
+ {
102
+ "type": "folder",
103
+ "id": "0",
104
+ "sequence_id": null,
105
+ "etag": null,
106
+ "name": "All Files"
107
+ }
108
+ ]
109
+ },
110
+ "created_by": {
111
+ "type": "user",
112
+ "id": "000000000",
113
+ "name": "Example User",
114
+ "login": "test@example.com"
115
+ },
116
+ "modified_by": {
117
+ "type": "user",
118
+ "id": "000000000",
119
+ "name": "Example User",
120
+ "login": "test@example.com"
121
+ },
122
+ "trashed_at": null,
123
+ "purged_at": null,
124
+ "content_created_at": "2013-04-12T13:53:52-07:00",
125
+ "content_modified_at": "2013-04-12T13:54:25-07:00",
126
+ "owned_by": {
127
+ "type": "user",
128
+ "id": "000000000",
129
+ "name": "Example User",
130
+ "login": "test@example.com"
131
+ },
132
+ "shared_link": null,
133
+ "folder_upload_email": null,
134
+ "parent": {
135
+ "type": "folder",
136
+ "id": "0",
137
+ "sequence_id": null,
138
+ "etag": null,
139
+ "name": "All Files"
140
+ },
141
+ "item_status": "active",
142
+ "synced": false
143
+ }
144
+ },
145
+ {
146
+ "type": "event",
147
+ "event_id": "dd4cba8afb2acb3cc0ecc43c81e565e78886494d",
148
+ "created_by": {
149
+ "type": "user",
150
+ "id": "000000000",
151
+ "name": "Example User",
152
+ "login": "test@example.com"
153
+ },
154
+ "created_at": "2013-04-12T14:02:06-07:00",
155
+ "recorded_at": "2013-04-12T14:02:06-07:00",
156
+ "event_type": "TAG_ITEM_CREATE",
157
+ "session_id": "d223c5ba4f4eb1d0b4fb55a",
158
+ "source": null
159
+ }
160
+ ]
161
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-box
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Attachments.me
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-19 00:00:00.000000000 Z
11
+ date: 2013-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
@@ -113,6 +113,8 @@ files:
113
113
  - lib/ruby-box/client.rb
114
114
  - lib/ruby-box/comment.rb
115
115
  - lib/ruby-box/discussion.rb
116
+ - lib/ruby-box/event.rb
117
+ - lib/ruby-box/event_response.rb
116
118
  - lib/ruby-box/exceptions.rb
117
119
  - lib/ruby-box/file.rb
118
120
  - lib/ruby-box/folder.rb
@@ -121,7 +123,9 @@ files:
121
123
  - lib/ruby-box/user.rb
122
124
  - ruby-box.gemspec
123
125
  - spec/client_spec.rb
126
+ - spec/event_spec.rb
124
127
  - spec/file_spec.rb
128
+ - spec/fixtures/events.json
125
129
  - spec/fixtures/遠志教授.jpg
126
130
  - spec/folder_spec.rb
127
131
  - spec/helper/account.example