inbox 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +18 -0
- data/LICENSE.txt +22 -0
- data/README.md +162 -74
- data/Rakefile +35 -30
- data/VERSION +1 -0
- data/example/.gitignore +16 -0
- data/example/Gemfile +39 -0
- data/example/README.rdoc +28 -0
- data/{test/dummy → example}/Rakefile +1 -2
- data/{app/views/inbox/emails/index.html.erb → example/app/assets/images/.keep} +0 -0
- data/example/app/assets/javascripts/application.js +16 -0
- data/example/app/assets/javascripts/welcome.js.coffee +3 -0
- data/example/app/assets/stylesheets/application.css +15 -0
- data/example/app/assets/stylesheets/welcome.css.scss +3 -0
- data/example/app/controllers/application_controller.rb +61 -0
- data/{test/dummy/db/development.sqlite3 → example/app/controllers/concerns/.keep} +0 -0
- data/{test/dummy → example}/app/helpers/application_helper.rb +0 -0
- data/example/app/helpers/welcome_helper.rb +2 -0
- data/{test/dummy/db/production.sqlite3 → example/app/mailers/.keep} +0 -0
- data/{test/dummy/db/test.sqlite3 → example/app/models/.keep} +0 -0
- data/{test/dummy/log/test.log → example/app/models/concerns/.keep} +0 -0
- data/example/app/views/layouts/application.html.erb +14 -0
- data/example/app/views/welcome/index.html.erb +2 -0
- data/example/bin/bundle +3 -0
- data/example/bin/rails +8 -0
- data/example/bin/rake +8 -0
- data/example/bin/spring +18 -0
- data/{test/dummy → example}/config.ru +1 -1
- data/example/config/application.rb +23 -0
- data/example/config/boot.rb +4 -0
- data/{test/dummy → example}/config/database.yml +8 -8
- data/example/config/environment.rb +5 -0
- data/example/config/environments/development.rb +39 -0
- data/example/config/environments/production.rb +82 -0
- data/example/config/environments/test.rb +41 -0
- data/example/config/initializers/assets.rb +8 -0
- data/{test/dummy → example}/config/initializers/backtrace_silencers.rb +1 -1
- data/example/config/initializers/cookies_serializer.rb +3 -0
- data/example/config/initializers/filter_parameter_logging.rb +4 -0
- data/example/config/initializers/inflections.rb +16 -0
- data/{test/dummy → example}/config/initializers/mime_types.rb +0 -1
- data/example/config/initializers/session_store.rb +3 -0
- data/{test/dummy → example}/config/initializers/wrap_parameters.rb +6 -6
- data/example/config/locales/en.yml +23 -0
- data/example/config/routes.rb +59 -0
- data/example/config/secrets.yml +22 -0
- data/example/db/seeds.rb +7 -0
- data/{test/dummy/public/favicon.ico → example/lib/assets/.keep} +0 -0
- data/example/lib/tasks/.keep +0 -0
- data/example/log/.keep +0 -0
- data/example/public/404.html +67 -0
- data/example/public/422.html +67 -0
- data/example/public/500.html +66 -0
- data/example/public/favicon.ico +0 -0
- data/example/public/robots.txt +5 -0
- data/example/test/controllers/.keep +0 -0
- data/example/test/controllers/welcome_controller_test.rb +9 -0
- data/example/test/fixtures/.keep +0 -0
- data/example/test/fixtures/users.yml +11 -0
- data/example/test/helpers/.keep +0 -0
- data/example/test/helpers/welcome_helper_test.rb +4 -0
- data/example/test/integration/.keep +0 -0
- data/example/test/mailers/.keep +0 -0
- data/example/test/models/.keep +0 -0
- data/{test/integration/navigation_test.rb → example/test/models/user_test.rb} +1 -4
- data/example/test/test_helper.rb +10 -0
- data/example/vendor/assets/javascripts/.keep +0 -0
- data/example/vendor/assets/stylesheets/.keep +0 -0
- data/inbox.gemspec +327 -0
- data/lib/contact.rb +10 -0
- data/lib/draft.rb +28 -0
- data/lib/file.rb +31 -0
- data/lib/inbox.rb +81 -20
- data/lib/message.rb +37 -0
- data/lib/namespace.rb +51 -0
- data/lib/restful_model.rb +76 -0
- data/lib/restful_model_collection.rb +131 -0
- data/lib/tag.rb +9 -0
- data/lib/thread.rb +60 -0
- data/lib/version.rb +3 -0
- data/spec/inbox_spec.rb +79 -0
- data/spec/restful_model_spec.rb +18 -0
- data/spec/spec_helper.rb +1 -0
- data/tasks/rspec.rake +3 -0
- metadata +1038 -181
- data/MIT-LICENSE +0 -20
- data/app/assets/images/inbox/results_bg.png +0 -0
- data/app/assets/images/inbox/tree_bg.png +0 -0
- data/app/assets/javascripts/inbox/application.js +0 -8
- data/app/assets/javascripts/inbox/emails.js +0 -2
- data/app/assets/stylesheets/inbox/application.css +0 -7
- data/app/assets/stylesheets/inbox/emails.css +0 -59
- data/app/assets/stylesheets/inbox/panel.css.erb +0 -229
- data/app/assets/stylesheets/inbox/reset.css +0 -53
- data/app/controllers/inbox/application_controller.rb +0 -4
- data/app/controllers/inbox/emails_controller.rb +0 -52
- data/app/helpers/inbox/application_helper.rb +0 -4
- data/app/helpers/inbox/emails_helper.rb +0 -4
- data/app/mailers/inbox/email_mailer.rb +0 -11
- data/app/models/inbox/email.rb +0 -51
- data/app/views/inbox/emails/new.html.erb +0 -9
- data/app/views/inbox/emails/show.html.erb +0 -48
- data/app/views/layouts/inbox/application.html.erb +0 -15
- data/app/views/layouts/inbox/inbox.html.erb +0 -25
- data/config/routes.rb +0 -6
- data/lib/inbox/engine.rb +0 -9
- data/lib/inbox/version.rb +0 -3
- data/lib/tasks/inbox_tasks.rake +0 -4
- data/test/dummy/app/assets/javascripts/application.js +0 -9
- data/test/dummy/app/assets/stylesheets/application.css +0 -7
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config/application.rb +0 -45
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -32
- data/test/dummy/config/environments/production.rb +0 -60
- data/test/dummy/config/environments/test.rb +0 -42
- data/test/dummy/config/initializers/inflections.rb +0 -10
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -4
- data/test/dummy/log/development.log +0 -3641
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -26
- data/test/dummy/script/rails +0 -6
- data/test/dummy/tmp/cache/assets/C4D/8B0/sprockets%2F5e1b589842222e2ea0043890c2c84539 +0 -0
- data/test/dummy/tmp/cache/assets/C6F/5C0/sprockets%2F259fb59d511a70d46436201b6770a04a +0 -0
- data/test/dummy/tmp/cache/assets/CF2/F90/sprockets%2F5378bb2470df984ccf2643991a6e476d +0 -0
- data/test/dummy/tmp/cache/assets/D0B/330/sprockets%2F582a2b19d6be92a0393afa63894d721a +0 -0
- data/test/dummy/tmp/cache/assets/D1B/CE0/sprockets%2F09c9c18794df089e62443d3debb117e5 +0 -0
- data/test/dummy/tmp/cache/assets/D1D/BA0/sprockets%2F29888f599d35bb11e4a8183d6dc5e23a +0 -0
- data/test/dummy/tmp/cache/assets/D1F/600/sprockets%2Fdd3578c9bd0719efe092c59655a25c55 +0 -0
- data/test/dummy/tmp/cache/assets/D21/920/sprockets%2F85fd59fe11746a33f5f917a923d84be3 +0 -0
- data/test/dummy/tmp/cache/assets/D4D/FB0/sprockets%2Fd5743837e8babdab4825364c4ee86f73 +0 -0
- data/test/dummy/tmp/cache/assets/D4F/520/sprockets%2F88ecb483df9e177ee775202ba0691ec7 +0 -0
- data/test/dummy/tmp/cache/assets/D6E/300/sprockets%2Fcc54b61039f74d6b8a2a7d04ad9d77f0 +0 -0
- data/test/dummy/tmp/cache/assets/D74/390/sprockets%2F5eda33e637dd54ff6a27bb76c482a473 +0 -0
- data/test/dummy/tmp/cache/assets/D76/170/sprockets%2Ffa5e461b362e11c80d5fd9e877fb63e2 +0 -0
- data/test/dummy/tmp/cache/assets/D7F/2D0/sprockets%2F141c2c9cb5235c8d21a00fbc8d7a2ab1 +0 -0
- data/test/dummy/tmp/cache/assets/D84/AA0/sprockets%2F5e841fe9d79e3ebf4333be8842b77bc5 +0 -0
- data/test/dummy/tmp/cache/assets/DA0/520/sprockets%2Fb8e93a54478c1f1a0e750ef2cbf74f3c +0 -0
- data/test/dummy/tmp/cache/assets/DC1/520/sprockets%2Feb8cea402f0bf04560adcd0cb8807b88 +0 -0
- data/test/dummy/tmp/mails/1345541756.4616725 +0 -11
- data/test/functional/inbox/email_test.rb +0 -9
- data/test/functional/inbox/emails_controller_test.rb +0 -16
- data/test/inbox_test.rb +0 -7
- data/test/test_helper.rb +0 -10
- data/test/unit/helpers/inbox/emails_helper_test.rb +0 -6
data/lib/message.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'restful_model'
|
2
|
+
require 'file'
|
3
|
+
|
4
|
+
module Inbox
|
5
|
+
class Message < RestfulModel
|
6
|
+
|
7
|
+
attr_accessor :subject
|
8
|
+
attr_accessor :from
|
9
|
+
attr_accessor :to
|
10
|
+
attr_accessor :cc
|
11
|
+
attr_accessor :bcc
|
12
|
+
attr_accessor :date
|
13
|
+
attr_accessor :thread_id
|
14
|
+
attr_accessor :file_ids
|
15
|
+
attr_accessor :body
|
16
|
+
|
17
|
+
def inflate(json)
|
18
|
+
super
|
19
|
+
@thread_id = json[:thread]
|
20
|
+
@file_ids = json[:files] || []
|
21
|
+
@to ||= []
|
22
|
+
@cc ||= []
|
23
|
+
@bcc ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
def as_json()
|
27
|
+
json = super
|
28
|
+
json[:files] = json[:file_ids]
|
29
|
+
json
|
30
|
+
end
|
31
|
+
|
32
|
+
def files
|
33
|
+
@files ||= RestfulModelCollection.new(File, @_api, @namespace, {:message=>@id})
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/namespace.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'restful_model'
|
2
|
+
require 'tag'
|
3
|
+
require 'message'
|
4
|
+
require 'draft'
|
5
|
+
require 'contact'
|
6
|
+
require 'file'
|
7
|
+
|
8
|
+
# Rather than saying require 'thread', we need to explicitly force
|
9
|
+
# the thread model to load. Otherwise, we can't reference it below.
|
10
|
+
# Thread still refers to the built-in Thread type, and Inbox::Thread
|
11
|
+
# is undefined.
|
12
|
+
load "thread.rb"
|
13
|
+
|
14
|
+
module Inbox
|
15
|
+
|
16
|
+
class Namespace < RestfulModel
|
17
|
+
|
18
|
+
attr_accessor :email_address
|
19
|
+
attr_accessor :provider
|
20
|
+
attr_accessor :account
|
21
|
+
|
22
|
+
def self.collection_name
|
23
|
+
"n"
|
24
|
+
end
|
25
|
+
|
26
|
+
def threads
|
27
|
+
@threads ||= RestfulModelCollection.new(Thread, @_api, @id)
|
28
|
+
end
|
29
|
+
|
30
|
+
def tags
|
31
|
+
@tags ||= RestfulModelCollection.new(Tag, @_api, @id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def messages
|
35
|
+
@messages ||= RestfulModelCollection.new(Message, @_api, @id)
|
36
|
+
end
|
37
|
+
|
38
|
+
def files
|
39
|
+
@files ||= RestfulModelCollection.new(File, @_api, @id)
|
40
|
+
end
|
41
|
+
|
42
|
+
def drafts
|
43
|
+
@drafts ||= RestfulModelCollection.new(Draft, @_api, @id)
|
44
|
+
end
|
45
|
+
|
46
|
+
def contacts
|
47
|
+
@contacts ||= RestfulModelCollection.new(Contact, @_api, @id)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Inbox
|
2
|
+
class RestfulModel
|
3
|
+
|
4
|
+
attr_accessor :id
|
5
|
+
attr_accessor :namespace
|
6
|
+
attr_accessor :created_at
|
7
|
+
|
8
|
+
def self.collection_name
|
9
|
+
"#{self.to_s.downcase}s".split('::').last
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(api, namespace = nil)
|
13
|
+
raise StandardError.new unless api.class <= Inbox::API
|
14
|
+
@namespace = namespace
|
15
|
+
@_api = api
|
16
|
+
end
|
17
|
+
|
18
|
+
def ==(comparison_object)
|
19
|
+
comparison_object.equal?(self) || (comparison_object.instance_of?(self.class) && comparison_object.id == id)
|
20
|
+
end
|
21
|
+
|
22
|
+
def inflate(json)
|
23
|
+
setters = methods.grep(/^\w+=$/)
|
24
|
+
setters.each do |setter|
|
25
|
+
property_name = setter.to_s.sub('=', '')
|
26
|
+
send(setter, json[property_name]) if json.has_key?(property_name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def save!
|
31
|
+
if id
|
32
|
+
update('PUT', '', as_json())
|
33
|
+
else
|
34
|
+
update('POST', '', as_json())
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def url(action = "")
|
39
|
+
action = "/#{action}" unless action.empty?
|
40
|
+
@_api.url_for_path("/n/#{@namespace}/#{self.class.collection_name}/#{id}#{action}")
|
41
|
+
end
|
42
|
+
|
43
|
+
def as_json(options = {})
|
44
|
+
hash = {}
|
45
|
+
setters = methods.grep(/^\w+=$/)
|
46
|
+
setters.each do |setter|
|
47
|
+
getter = setter.to_s.sub('=', '')
|
48
|
+
unless options[:except] && options[:except].include?(getter)
|
49
|
+
value = send(getter)
|
50
|
+
unless value.is_a?(RestfulModelCollection)
|
51
|
+
value = value.as_json(options) if value.respond_to?(:as_json)
|
52
|
+
hash[getter] = value
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
hash
|
57
|
+
end
|
58
|
+
|
59
|
+
def update(http_method, action, data = {})
|
60
|
+
http_method = http_method.downcase
|
61
|
+
|
62
|
+
::RestClient.send(http_method, self.url(action), data.to_json, :content_type => :json) do |response, request, result|
|
63
|
+
unless http_method == 'delete'
|
64
|
+
json = Inbox.interpret_response(result, response, :expected_class => Object)
|
65
|
+
inflate(json)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
self
|
69
|
+
end
|
70
|
+
|
71
|
+
def destroy
|
72
|
+
update('DELETE', '')
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'restful_model'
|
2
|
+
|
3
|
+
module Inbox
|
4
|
+
class RestfulModelCollection
|
5
|
+
|
6
|
+
attr_accessor :filters
|
7
|
+
|
8
|
+
def initialize(model_class, api, namespace, filters = {})
|
9
|
+
raise StandardError.new unless api.class <= Inbox::API
|
10
|
+
@model_class = model_class
|
11
|
+
@filters = filters
|
12
|
+
@namespace = namespace
|
13
|
+
@_api = api
|
14
|
+
end
|
15
|
+
|
16
|
+
def each
|
17
|
+
offset = 0
|
18
|
+
finished = false
|
19
|
+
while (!finished) do
|
20
|
+
items = get_model_collection(offset)
|
21
|
+
break if items.length == 0
|
22
|
+
items.each { |item|
|
23
|
+
yield item
|
24
|
+
}
|
25
|
+
offset += items.length
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def first
|
30
|
+
get_model_collection.first
|
31
|
+
end
|
32
|
+
|
33
|
+
def all
|
34
|
+
range(0, Float::INFINITY)
|
35
|
+
end
|
36
|
+
|
37
|
+
def where(filters)
|
38
|
+
collection = self.clone
|
39
|
+
collection.filters = filters
|
40
|
+
collection
|
41
|
+
end
|
42
|
+
|
43
|
+
def range(offset = 0, limit = 50)
|
44
|
+
accumulated = []
|
45
|
+
finished = false
|
46
|
+
chunk_size = 50
|
47
|
+
|
48
|
+
while (!finished && accumulated.length < limit) do
|
49
|
+
results = get_model_collection(offset + accumulated.length, chunk_size)
|
50
|
+
accumulated = accumulated.concat(results)
|
51
|
+
|
52
|
+
# we're done if we have more than 'limit' items, or if we asked for 50 and got less than 50...
|
53
|
+
finished = accumulated.length >= limit || results.length == 0 || (results.length % chunk_size != 0)
|
54
|
+
end
|
55
|
+
|
56
|
+
accumulated = accumulated[0..limit] if limit < Float::INFINITY
|
57
|
+
accumulated
|
58
|
+
end
|
59
|
+
|
60
|
+
def delete(item_or_id)
|
61
|
+
item_or_id = item_or_id.id if item_or_id.is_a?(RestfulModel)
|
62
|
+
RestClient.delete("#{url}/#{id}")
|
63
|
+
end
|
64
|
+
|
65
|
+
def find(id)
|
66
|
+
return nil unless id
|
67
|
+
get_model(id)
|
68
|
+
end
|
69
|
+
|
70
|
+
def build(args)
|
71
|
+
for key in args.keys
|
72
|
+
args[key.to_s] = args[key]
|
73
|
+
end
|
74
|
+
model = @model_class.new(@_api, @namespace)
|
75
|
+
model.inflate(args)
|
76
|
+
model
|
77
|
+
end
|
78
|
+
|
79
|
+
def inflate_collection(items = [])
|
80
|
+
models = []
|
81
|
+
|
82
|
+
return unless items.is_a?(Array)
|
83
|
+
items.each do |json|
|
84
|
+
if @model_class < RestfulModel
|
85
|
+
model = @model_class.new(@_api)
|
86
|
+
model.inflate(json)
|
87
|
+
else
|
88
|
+
model = @model_class.new(json)
|
89
|
+
end
|
90
|
+
models.push(model)
|
91
|
+
end
|
92
|
+
models
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def url
|
98
|
+
prefix = "/n/#{@namespace}" if @namespace
|
99
|
+
@_api.url_for_path("#{prefix}/#{@model_class.collection_name}")
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_model(id)
|
103
|
+
model = nil
|
104
|
+
|
105
|
+
RestClient.get("#{url}/#{id}"){ |response,request,result|
|
106
|
+
json = Inbox.interpret_response(result, response, {:expected_class => Object})
|
107
|
+
if @model_class < RestfulModel
|
108
|
+
model = @model_class.new(@_api)
|
109
|
+
model.inflate(json)
|
110
|
+
else
|
111
|
+
model = @model_class.new(json)
|
112
|
+
end
|
113
|
+
}
|
114
|
+
model
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_model_collection(offset = 0, limit = 50)
|
118
|
+
filters = @filters.clone
|
119
|
+
filters[:offset] = offset
|
120
|
+
filters[:limit] = limit
|
121
|
+
models = []
|
122
|
+
|
123
|
+
RestClient.get("#{url}?#{filters.to_query}"){ |response,request,result|
|
124
|
+
items = Inbox.interpret_response(result, response, {:expected_class => Array})
|
125
|
+
models = inflate_collection(items)
|
126
|
+
}
|
127
|
+
models
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
data/lib/tag.rb
ADDED
data/lib/thread.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'restful_model'
|
2
|
+
|
3
|
+
module Inbox
|
4
|
+
class Thread < RestfulModel
|
5
|
+
|
6
|
+
attr_accessor :subject
|
7
|
+
attr_accessor :participants
|
8
|
+
attr_accessor :last_message_timestamp
|
9
|
+
attr_accessor :first_message_timestamp
|
10
|
+
attr_accessor :snippet
|
11
|
+
attr_accessor :tags
|
12
|
+
attr_accessor :message_ids
|
13
|
+
attr_accessor :draft_ids
|
14
|
+
|
15
|
+
def inflate(json)
|
16
|
+
super
|
17
|
+
message_ids = json[:messages]
|
18
|
+
draft_ids = json[:drafts]
|
19
|
+
end
|
20
|
+
|
21
|
+
def messages
|
22
|
+
@messages ||= RestfulModelCollection.new(Message, @_api, @namespace, {:thread=>@id})
|
23
|
+
end
|
24
|
+
|
25
|
+
def drafts
|
26
|
+
@drafts ||= RestfulModelCollection.new(Draft, @_api, @namespace, {:thread=>@id})
|
27
|
+
end
|
28
|
+
|
29
|
+
def update_tags!(tags_to_add = [], tags_to_remove = [])
|
30
|
+
update('PUT', '', {
|
31
|
+
:add_tags => tags_to_add,
|
32
|
+
:remove_tags => tags_to_remove
|
33
|
+
})
|
34
|
+
end
|
35
|
+
|
36
|
+
def mark_as_read!
|
37
|
+
update_tags!([], ['unread'])
|
38
|
+
end
|
39
|
+
|
40
|
+
def mark_as_seen!
|
41
|
+
update_tags!([], ['unseen'])
|
42
|
+
end
|
43
|
+
|
44
|
+
def archive!
|
45
|
+
update_tags!(['archive'], ['inbox'])
|
46
|
+
end
|
47
|
+
|
48
|
+
def unarchive!
|
49
|
+
update_tags!(['inbox'], ['archive'])
|
50
|
+
end
|
51
|
+
|
52
|
+
def star!
|
53
|
+
update_tags!(['starred'], [''])
|
54
|
+
end
|
55
|
+
|
56
|
+
def unstar!
|
57
|
+
update_tags!([], ['starred'])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/version.rb
ADDED
data/spec/inbox_spec.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
::ENV['RACK_ENV'] = 'test'
|
2
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
3
|
+
|
4
|
+
describe 'Inbox' do
|
5
|
+
before (:each) do
|
6
|
+
@app_id = 'ABC'
|
7
|
+
@app_secret = '123'
|
8
|
+
@auth_token = 'UXXMOCJW-BKSLPCFI-UQAQFWLO'
|
9
|
+
@inbox = Inbox::API.new(@app_id, @app_secret, @auth_token)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#url_for_path" do
|
13
|
+
it "should return the url for a provided path" do
|
14
|
+
expect(@inbox.url_for_path('/wobble')).to eq("https://#{@inbox.auth_token}:@api.inboxapp.com/wobble")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return an error if you have not provided an auth token" do
|
18
|
+
@inbox = Inbox::API.new(@app_id, @app_secret)
|
19
|
+
expect {
|
20
|
+
@inbox.url_for_path('/wobble')
|
21
|
+
}.to raise_error(Inbox::NoAuthToken)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#self.interpret_response" do
|
26
|
+
before (:each) do
|
27
|
+
@result = double('result')
|
28
|
+
allow(@result).to receive(:code).and_return(200)
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when an expected_class is provided" do
|
32
|
+
context "when the server responds with a 200 but unknown, invalid body" do
|
33
|
+
it "should raise an UnexpectedResponse" do
|
34
|
+
expect {
|
35
|
+
Inbox.interpret_response(@result, "I AM NOT JSON", {:expected_class => Array})
|
36
|
+
}.to raise_error(Inbox::UnexpectedResponse)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when the server responds with JSON that does not represent an array" do
|
41
|
+
it "should raise an UnexpectedResponse" do
|
42
|
+
allow(@result).to receive(:code).and_return(500)
|
43
|
+
expect {
|
44
|
+
Inbox.interpret_response(@result, "{\"_id\":\"5107089add02dcaecc000003\",\"created_at\":\"2013-01-28T23:24:10Z\",\"domain\":\"generic\",\"name\":\"Untitled\",\"password\":null,\"slug\":\"\",\"tracers\":[{\"_id\":\"5109b5e0dd02dc5976000001\",\"created_at\":\"2013-01-31T00:08:00Z\",\"name\":\"Facebook\"},{\"_id\":\"5109b5f5dd02dc4c43000002\",\"created_at\":\"2013-01-31T00:08:21Z\",\"name\":\"Twitter\"}],\"published_pop_url\":\"http://group3.lvh.me\",\"unpopulated_api_tags\":[],\"unpopulated_api_regions\":[],\"label_names\":[]}", {:expected_class => Array})
|
45
|
+
}.to raise_error(Inbox::UnexpectedResponse)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "when the server responds with a 403" do
|
51
|
+
it "should raise AccessDenied" do
|
52
|
+
allow(@result).to receive(:code).and_return(403)
|
53
|
+
expect {
|
54
|
+
Inbox.interpret_response(@result, '')
|
55
|
+
}.to raise_error(Inbox::AccessDenied)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when the server responds with a 404" do
|
60
|
+
it "should raise ResourceNotFound" do
|
61
|
+
allow(@result).to receive(:code).and_return(404)
|
62
|
+
expect {
|
63
|
+
Inbox.interpret_response(@result, '')
|
64
|
+
}.to raise_error(Inbox::ResourceNotFound)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when the server responds with another status code" do
|
69
|
+
it "should raise an UnexpectedResponse" do
|
70
|
+
allow(@result).to receive(:code).and_return(500)
|
71
|
+
expect {
|
72
|
+
Inbox.interpret_response(@result, '')
|
73
|
+
}.to raise_error(Inbox::UnexpectedResponse)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|