moromi-request_header 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: f1866e95548f3bc4b8418e5fa4af51863385582d
4
+ data.tar.gz: fdf987d6321e835e519021bccda5dab8b49dfdb3
5
+ SHA512:
6
+ metadata.gz: b2dd2404da1d26a75b66535cb2a7df5e616b99fa4bcb939ccf3d56e7070165c661c133ba1525dd1e833d0ec3a2382b1a18da0febb0050d9680e7a48c1577a655
7
+ data.tar.gz: 98c3fcac74ee6da72d5c41e066677b3674cb4514e0e6d409de662732d7b7314ee4b0db7ac520871b68dd7e29775e90b38bedeb89b6b5bbecf471bc058ddbcf9e
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in moromi-request_header.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 moromi
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # Moromi::Apns
2
+
3
+ [![Latest Version](https://img.shields.io/gem/v/moromi-request_header.svg)](http://rubygems.org/gems/moromi-request_header)
4
+ [![Circle CI](https://circleci.com/gh/moromi/moromi-request_header.svg?style=svg)](https://circleci.com/gh/moromi/moromi-request_header)
5
+
6
+ APNS model.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'moromi-request_header'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install moromi-request_header
23
+
24
+ ## Usage
25
+
26
+ - initializers/moromi/request_header.rb
27
+
28
+ ```ruby
29
+ Moromi::RequestHeader.configure do |config|
30
+ config.app_name = 'moromi'
31
+ end
32
+ ```
33
+
34
+ - append to application_controller.rb
35
+
36
+ ```ruby
37
+ class ApplicationController < ActionController::Base
38
+ def custom_header
39
+ @custom_header ||= Moromi::RequestHeader::Ios.new(headers: request.headers)
40
+ end
41
+ end
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ 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).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/moromi/moromi-request_header.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "moromi/request_header"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ dependencies:
2
+ pre:
3
+ - >
4
+ case $CIRCLE_NODE_INDEX in
5
+ 0)
6
+ rvm use 2.3.3 --default
7
+ ;;
8
+ 1)
9
+ rvm use 2.2.6 --default
10
+ ;;
11
+ 3)
12
+ rvm use 2.1.10 --default
13
+ ;;
14
+ esac
15
+ test:
16
+ override:
17
+ - ruby -v && bundle exec rspec: {parallel: true}
@@ -0,0 +1,16 @@
1
+ require 'moromi/request_header/version'
2
+ require 'moromi/request_header/config'
3
+ require 'moromi/request_header/ios'
4
+
5
+ module Moromi
6
+ module RequestHeader
7
+ def self.configure(&block)
8
+ yield config
9
+ end
10
+
11
+ # @return [Moromi::RequestHeader::Config]
12
+ def self.config
13
+ @config ||= Config.new
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ require 'active_support/configurable'
2
+
3
+ module Moromi
4
+ module RequestHeader
5
+ class Config
6
+ include ActiveSupport::Configurable
7
+
8
+ config_accessor :app_name
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,77 @@
1
+ require 'active_support/core_ext/string'
2
+
3
+ module Moromi
4
+ module RequestHeader
5
+ class Ios
6
+ PROPERTIES = %i(
7
+ token
8
+ bundle_identifier
9
+ bundle_version_string
10
+ bundle_version
11
+ os
12
+ os_version
13
+ device_model
14
+ device_uuid
15
+ seconds_from_gmt
16
+ language_code
17
+ region_code
18
+ )
19
+
20
+ attr_accessor *PROPERTIES
21
+
22
+ def initialize(headers: {}, app_name: nil)
23
+ @app_name = app_name || self.class::default_app_name
24
+
25
+ names = self.class::header_names(app_name: @app_name)
26
+ self.class::PROPERTIES.each do |property|
27
+ name = names[property]
28
+ send("#{property.to_s}=", headers[name]) rescue nil
29
+ end
30
+ end
31
+
32
+ def to_hash
33
+ {}.tap do |results|
34
+ self.class::header_names(app_name: @app_name).invert.each do |k, v|
35
+ results[k] = send(v) rescue nil
36
+ end
37
+ end
38
+ end
39
+
40
+ class << self
41
+ def default_app_name
42
+ Moromi::RequestHeader.config.app_name
43
+ end
44
+
45
+ def header_name(property, app_name: nil)
46
+ header_names(app_name: app_name).fetch(property.to_sym, nil)
47
+ end
48
+
49
+ def header_names(app_name: nil)
50
+ app_class_name = (app_name || default_app_name).classify
51
+
52
+ {
53
+ token: "X-#{app_class_name}-Token",
54
+ bundle_identifier: "X-#{app_class_name}-Bundle-Identifier",
55
+ bundle_version_string: "X-#{app_class_name}-Bundle-Version-String",
56
+ bundle_version: "X-#{app_class_name}-Bundle-Version",
57
+ os: "X-#{app_class_name}-Os",
58
+ os_version: "X-#{app_class_name}-Os-Version",
59
+ device_model: "X-#{app_class_name}-Device-Model",
60
+ device_uuid: "X-#{app_class_name}-Device-Uuid",
61
+ seconds_from_gmt: "X-#{app_class_name}-Seconds-From-Gmt",
62
+ language_code: "X-#{app_class_name}-Language-Code",
63
+ region_code: "X-#{app_class_name}-Region-Code"
64
+ }
65
+ end
66
+
67
+ def create(app_name: nil, args: {})
68
+ new(app_name: app_name).tap do |header|
69
+ PROPERTIES.each do |property|
70
+ header.send("#{property.to_s}=", args[property]) rescue nil
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,5 @@
1
+ module Moromi
2
+ module RequestHeader
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'moromi/request_header/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "moromi-request_header"
8
+ spec.version = Moromi::RequestHeader::VERSION
9
+ spec.authors = ["Takahiro Oishi"]
10
+ spec.email = ["takahiro.oishi@dena.jp"]
11
+
12
+ spec.summary = %q{Useful HTTP Header}
13
+ spec.description = %q{Useful HTTP Header}
14
+ spec.homepage = "https://github.com/moromi/moromi-request_header"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "activesupport"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.13"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moromi-request_header
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takahiro Oishi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '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.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Useful HTTP Header
70
+ email:
71
+ - takahiro.oishi@dena.jp
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - circle.yml
85
+ - lib/moromi/request_header.rb
86
+ - lib/moromi/request_header/config.rb
87
+ - lib/moromi/request_header/ios.rb
88
+ - lib/moromi/request_header/version.rb
89
+ - moromi-request_header.gemspec
90
+ homepage: https://github.com/moromi/moromi-request_header
91
+ licenses: []
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.5.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Useful HTTP Header
113
+ test_files: []