fetch-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0cc2d43fdc254d4a5f437fad09cf3aa5d2a2479e
4
+ data.tar.gz: 1b7dc7cb274b3c0cbe14cc40b543d9fd50fdea9a
5
+ SHA512:
6
+ metadata.gz: 107bfdd6f745c7558f85b9a81b2bc602bb2158b08bdfe377b8ff106c63411ae343ff1f9ba6d900ea0094da6c3117072d958dcf709c27c545d18cf337700c466f
7
+ data.tar.gz: 618b0d7b56a4a92282927867050b4278cf9ed77fedab910c4a3130de728fe64d75d7a37c5f7900945bd8dae811f7da972d5deaf636c2847a95291d2a8d1bfad8
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fetch-rails.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Vipul A M
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Fetch::Rails
2
+
3
+ A window.fetch polyfill for browser from Rails using https://github.com/github/fetch
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fetch-rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fetch-rails
20
+
21
+ ## Usage
22
+
23
+ Add require fetch to application.js
24
+
25
+ //= require fetch
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/vipulnsward/fetch-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fetch/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fetch-rails"
8
+ spec.version = Fetch::Rails::VERSION
9
+ spec.authors = ["Vipul A M"]
10
+ spec.email = ["vipulnsward@gmail.com"]
11
+
12
+ spec.summary = %q{A window.fetch polyfill for browser from Rails using https://github.com/github/fetch}
13
+ spec.description = %q{A window.fetch polyfill for browser from Rails using https://github.com/github/fetch}
14
+ spec.homepage = "https://github.com/vipulnsward/fetch-rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "rails", ">= 4.1.0"
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest"
26
+ end
@@ -0,0 +1,349 @@
1
+ (function() {
2
+ 'use strict';
3
+
4
+ if (self.fetch) {
5
+ return
6
+ }
7
+
8
+ function normalizeName(name) {
9
+ if (typeof name !== 'string') {
10
+ name = String(name)
11
+ }
12
+ if (/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(name)) {
13
+ throw new TypeError('Invalid character in header field name')
14
+ }
15
+ return name.toLowerCase()
16
+ }
17
+
18
+ function normalizeValue(value) {
19
+ if (typeof value !== 'string') {
20
+ value = String(value)
21
+ }
22
+ return value
23
+ }
24
+
25
+ function Headers(headers) {
26
+ this.map = {}
27
+
28
+ if (headers instanceof Headers) {
29
+ headers.forEach(function(value, name) {
30
+ this.append(name, value)
31
+ }, this)
32
+
33
+ } else if (headers) {
34
+ Object.getOwnPropertyNames(headers).forEach(function(name) {
35
+ this.append(name, headers[name])
36
+ }, this)
37
+ }
38
+ }
39
+
40
+ Headers.prototype.append = function(name, value) {
41
+ name = normalizeName(name)
42
+ value = normalizeValue(value)
43
+ var list = this.map[name]
44
+ if (!list) {
45
+ list = []
46
+ this.map[name] = list
47
+ }
48
+ list.push(value)
49
+ }
50
+
51
+ Headers.prototype['delete'] = function(name) {
52
+ delete this.map[normalizeName(name)]
53
+ }
54
+
55
+ Headers.prototype.get = function(name) {
56
+ var values = this.map[normalizeName(name)]
57
+ return values ? values[0] : null
58
+ }
59
+
60
+ Headers.prototype.getAll = function(name) {
61
+ return this.map[normalizeName(name)] || []
62
+ }
63
+
64
+ Headers.prototype.has = function(name) {
65
+ return this.map.hasOwnProperty(normalizeName(name))
66
+ }
67
+
68
+ Headers.prototype.set = function(name, value) {
69
+ this.map[normalizeName(name)] = [normalizeValue(value)]
70
+ }
71
+
72
+ Headers.prototype.forEach = function(callback, thisArg) {
73
+ Object.getOwnPropertyNames(this.map).forEach(function(name) {
74
+ this.map[name].forEach(function(value) {
75
+ callback.call(thisArg, value, name, this)
76
+ }, this)
77
+ }, this)
78
+ }
79
+
80
+ function consumed(body) {
81
+ if (body.bodyUsed) {
82
+ return Promise.reject(new TypeError('Already read'))
83
+ }
84
+ body.bodyUsed = true
85
+ }
86
+
87
+ function fileReaderReady(reader) {
88
+ return new Promise(function(resolve, reject) {
89
+ reader.onload = function() {
90
+ resolve(reader.result)
91
+ }
92
+ reader.onerror = function() {
93
+ reject(reader.error)
94
+ }
95
+ })
96
+ }
97
+
98
+ function readBlobAsArrayBuffer(blob) {
99
+ var reader = new FileReader()
100
+ reader.readAsArrayBuffer(blob)
101
+ return fileReaderReady(reader)
102
+ }
103
+
104
+ function readBlobAsText(blob) {
105
+ var reader = new FileReader()
106
+ reader.readAsText(blob)
107
+ return fileReaderReady(reader)
108
+ }
109
+
110
+ var support = {
111
+ blob: 'FileReader' in self && 'Blob' in self && (function() {
112
+ try {
113
+ new Blob();
114
+ return true
115
+ } catch(e) {
116
+ return false
117
+ }
118
+ })(),
119
+ formData: 'FormData' in self
120
+ }
121
+
122
+ function Body() {
123
+ this.bodyUsed = false
124
+
125
+
126
+ this._initBody = function(body) {
127
+ this._bodyInit = body
128
+ if (typeof body === 'string') {
129
+ this._bodyText = body
130
+ } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
131
+ this._bodyBlob = body
132
+ } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
133
+ this._bodyFormData = body
134
+ } else if (!body) {
135
+ this._bodyText = ''
136
+ } else {
137
+ throw new Error('unsupported BodyInit type')
138
+ }
139
+ }
140
+
141
+ if (support.blob) {
142
+ this.blob = function() {
143
+ var rejected = consumed(this)
144
+ if (rejected) {
145
+ return rejected
146
+ }
147
+
148
+ if (this._bodyBlob) {
149
+ return Promise.resolve(this._bodyBlob)
150
+ } else if (this._bodyFormData) {
151
+ throw new Error('could not read FormData body as blob')
152
+ } else {
153
+ return Promise.resolve(new Blob([this._bodyText]))
154
+ }
155
+ }
156
+
157
+ this.arrayBuffer = function() {
158
+ return this.blob().then(readBlobAsArrayBuffer)
159
+ }
160
+
161
+ this.text = function() {
162
+ var rejected = consumed(this)
163
+ if (rejected) {
164
+ return rejected
165
+ }
166
+
167
+ if (this._bodyBlob) {
168
+ return readBlobAsText(this._bodyBlob)
169
+ } else if (this._bodyFormData) {
170
+ throw new Error('could not read FormData body as text')
171
+ } else {
172
+ return Promise.resolve(this._bodyText)
173
+ }
174
+ }
175
+ } else {
176
+ this.text = function() {
177
+ var rejected = consumed(this)
178
+ return rejected ? rejected : Promise.resolve(this._bodyText)
179
+ }
180
+ }
181
+
182
+ if (support.formData) {
183
+ this.formData = function() {
184
+ return this.text().then(decode)
185
+ }
186
+ }
187
+
188
+ this.json = function() {
189
+ return this.text().then(JSON.parse)
190
+ }
191
+
192
+ return this
193
+ }
194
+
195
+ // HTTP methods whose capitalization should be normalized
196
+ var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']
197
+
198
+ function normalizeMethod(method) {
199
+ var upcased = method.toUpperCase()
200
+ return (methods.indexOf(upcased) > -1) ? upcased : method
201
+ }
202
+
203
+ function Request(input, options) {
204
+ options = options || {}
205
+ var body = options.body
206
+ if (Request.prototype.isPrototypeOf(input)) {
207
+ if (input.bodyUsed) {
208
+ throw new TypeError('Already read')
209
+ }
210
+ this.url = input.url
211
+ this.credentials = input.credentials
212
+ if (!options.headers) {
213
+ this.headers = new Headers(input.headers)
214
+ }
215
+ this.method = input.method
216
+ this.mode = input.mode
217
+ if (!body) {
218
+ body = input._bodyInit
219
+ input.bodyUsed = true
220
+ }
221
+ } else {
222
+ this.url = input
223
+ }
224
+
225
+ this.credentials = options.credentials || this.credentials || 'omit'
226
+ if (options.headers || !this.headers) {
227
+ this.headers = new Headers(options.headers)
228
+ }
229
+ this.method = normalizeMethod(options.method || this.method || 'GET')
230
+ this.mode = options.mode || this.mode || null
231
+ this.referrer = null
232
+
233
+ if ((this.method === 'GET' || this.method === 'HEAD') && body) {
234
+ throw new TypeError('Body not allowed for GET or HEAD requests')
235
+ }
236
+ this._initBody(body)
237
+ }
238
+
239
+ function decode(body) {
240
+ var form = new FormData()
241
+ body.trim().split('&').forEach(function(bytes) {
242
+ if (bytes) {
243
+ var split = bytes.split('=')
244
+ var name = split.shift().replace(/\+/g, ' ')
245
+ var value = split.join('=').replace(/\+/g, ' ')
246
+ form.append(decodeURIComponent(name), decodeURIComponent(value))
247
+ }
248
+ })
249
+ return form
250
+ }
251
+
252
+ function headers(xhr) {
253
+ var head = new Headers()
254
+ var pairs = xhr.getAllResponseHeaders().trim().split('\n')
255
+ pairs.forEach(function(header) {
256
+ var split = header.trim().split(':')
257
+ var key = split.shift().trim()
258
+ var value = split.join(':').trim()
259
+ head.append(key, value)
260
+ })
261
+ return head
262
+ }
263
+
264
+ Body.call(Request.prototype)
265
+
266
+ function Response(bodyInit, options) {
267
+ if (!options) {
268
+ options = {}
269
+ }
270
+
271
+ this._initBody(bodyInit)
272
+ this.type = 'default'
273
+ this.url = null
274
+ this.status = options.status
275
+ this.ok = this.status >= 200 && this.status < 300
276
+ this.statusText = options.statusText
277
+ this.headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers)
278
+ this.url = options.url || ''
279
+ }
280
+
281
+ Body.call(Response.prototype)
282
+
283
+ self.Headers = Headers;
284
+ self.Request = Request;
285
+ self.Response = Response;
286
+
287
+ self.fetch = function(input, init) {
288
+ var request
289
+ if (Request.prototype.isPrototypeOf(input) && !init) {
290
+ request = input
291
+ } else {
292
+ request = new Request(input, init)
293
+ }
294
+
295
+ return new Promise(function(resolve, reject) {
296
+ var xhr = new XMLHttpRequest()
297
+
298
+ function responseURL() {
299
+ if ('responseURL' in xhr) {
300
+ return xhr.responseURL
301
+ }
302
+
303
+ // Avoid security warnings on getResponseHeader when not allowed by CORS
304
+ if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
305
+ return xhr.getResponseHeader('X-Request-URL')
306
+ }
307
+
308
+ return;
309
+ }
310
+
311
+ xhr.onload = function() {
312
+ var status = (xhr.status === 1223) ? 204 : xhr.status
313
+ if (status < 100 || status > 599) {
314
+ reject(new TypeError('Network request failed'))
315
+ return
316
+ }
317
+ var options = {
318
+ status: status,
319
+ statusText: xhr.statusText,
320
+ headers: headers(xhr),
321
+ url: responseURL()
322
+ }
323
+ var body = 'response' in xhr ? xhr.response : xhr.responseText;
324
+ resolve(new Response(body, options))
325
+ }
326
+
327
+ xhr.onerror = function() {
328
+ reject(new TypeError('Network request failed'))
329
+ }
330
+
331
+ xhr.open(request.method, request.url, true)
332
+
333
+ if (request.credentials === 'include') {
334
+ xhr.withCredentials = true
335
+ }
336
+
337
+ if ('responseType' in xhr && support.blob) {
338
+ xhr.responseType = 'blob'
339
+ }
340
+
341
+ request.headers.forEach(function(value, name) {
342
+ xhr.setRequestHeader(name, value)
343
+ })
344
+
345
+ xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit)
346
+ })
347
+ }
348
+ self.fetch.polyfill = true
349
+ })();
@@ -0,0 +1,4 @@
1
+ puts "I was called?"
2
+ require "fetch/rails/version"
3
+ require 'fetch/rails/railtie'
4
+
@@ -0,0 +1,15 @@
1
+ require 'rails'
2
+
3
+ module Fetch
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie
6
+ FETCH_GEM_ROOT = Pathname.new('../../../../').expand_path(__FILE__)
7
+
8
+ config.before_initialize do |app|
9
+ puts FETCH_GEM_ROOT.join('lib/assets/javascripts/').to_s
10
+ app.config.assets.paths << FETCH_GEM_ROOT.join('lib/assets/javascripts/').to_s
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Fetch
2
+ module Rails
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fetch-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vipul A M
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A window.fetch polyfill for browser from Rails using https://github.com/github/fetch
70
+ email:
71
+ - vipulnsward@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - fetch-rails.gemspec
84
+ - lib/assets/javascripts/fetch.js
85
+ - lib/fetch/rails.rb
86
+ - lib/fetch/rails/railtie.rb
87
+ - lib/fetch/rails/version.rb
88
+ homepage: https://github.com/vipulnsward/fetch-rails
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.5.1
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A window.fetch polyfill for browser from Rails using https://github.com/github/fetch
112
+ test_files: []