moromi-request_header 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f1866e95548f3bc4b8418e5fa4af51863385582d
4
- data.tar.gz: fdf987d6321e835e519021bccda5dab8b49dfdb3
2
+ SHA256:
3
+ metadata.gz: 8cfb14b9c6c726a05f5eb0470f63b03f2d56b07c6102da275bde45be89e654d6
4
+ data.tar.gz: 00e7df682c693abf22ed6f398999ea5266e2fac3571dc289a9a63e64eb451533
5
5
  SHA512:
6
- metadata.gz: b2dd2404da1d26a75b66535cb2a7df5e616b99fa4bcb939ccf3d56e7070165c661c133ba1525dd1e833d0ec3a2382b1a18da0febb0050d9680e7a48c1577a655
7
- data.tar.gz: 98c3fcac74ee6da72d5c41e066677b3674cb4514e0e6d409de662732d7b7314ee4b0db7ac520871b68dd7e29775e90b38bedeb89b6b5bbecf471bc058ddbcf9e
6
+ metadata.gz: 2718cd19c5f1d6a494544ee6984a2e8c848ec654ec2481bc3890feaaf5d851ce3a541ed8c4668daf9374c4e19a0511b7a12d356c2277b58fbb529402fda60bec
7
+ data.tar.gz: 936f25dacfc5fad0b9944bf990061c2bc4ed8c64cba8bf08443d3eead12351ccbbfe2deaf31e720e8197004a8441844b3bc47ebfddcf1d2abf683509043c572b
@@ -0,0 +1,23 @@
1
+ name: Ruby
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ strategy:
8
+ fail-fast: false
9
+ matrix:
10
+ os: [ubuntu-latest]
11
+ ruby: [2.7, 3.0]
12
+ runs-on: ${{ matrix.os }}
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
19
+ - run: |
20
+ gem install bundler
21
+ bundle config path vendor/bundle
22
+ bundle install --jobs 4 --retry 3
23
+ bundle exec rspec
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
- # Moromi::Apns
1
+ # Moromi::RequestHeader
2
2
 
3
3
  [![Latest Version](https://img.shields.io/gem/v/moromi-request_header.svg)](http://rubygems.org/gems/moromi-request_header)
4
4
  [![Circle CI](https://circleci.com/gh/moromi/moromi-request_header.svg?style=svg)](https://circleci.com/gh/moromi/moromi-request_header)
5
5
 
6
- APNS model.
7
-
8
6
  ## Installation
9
7
 
10
8
  Add this line to your application's Gemfile:
@@ -1,6 +1,7 @@
1
1
  require 'moromi/request_header/version'
2
2
  require 'moromi/request_header/config'
3
- require 'moromi/request_header/ios'
3
+ require 'moromi/request_header/core'
4
+ require 'moromi/request_header/default'
4
5
 
5
6
  module Moromi
6
7
  module RequestHeader
@@ -1,13 +1,17 @@
1
- require 'active_support/core_ext/string'
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
2
3
 
3
4
  module Moromi
4
5
  module RequestHeader
5
- class Ios
6
+ module Core
7
+ extend ActiveSupport::Concern
8
+
6
9
  PROPERTIES = %i(
7
10
  token
8
11
  bundle_identifier
9
12
  bundle_version_string
10
13
  bundle_version
14
+ platform
11
15
  os
12
16
  os_version
13
17
  device_model
@@ -15,7 +19,10 @@ module Moromi
15
19
  seconds_from_gmt
16
20
  language_code
17
21
  region_code
18
- )
22
+ ).freeze
23
+
24
+ PROPERTY_DEFAULT_VALUES = {
25
+ }.freeze
19
26
 
20
27
  attr_accessor *PROPERTIES
21
28
 
@@ -25,19 +32,24 @@ module Moromi
25
32
  names = self.class::header_names(app_name: @app_name)
26
33
  self.class::PROPERTIES.each do |property|
27
34
  name = names[property]
28
- send("#{property.to_s}=", headers[name]) rescue nil
35
+ value = headers[name] || PROPERTY_DEFAULT_VALUES[property]
36
+ public_send("#{property.to_s}=", value)
37
+ rescue
38
+ nil
29
39
  end
30
40
  end
31
41
 
32
42
  def to_hash
33
43
  {}.tap do |results|
34
44
  self.class::header_names(app_name: @app_name).invert.each do |k, v|
35
- results[k] = send(v) rescue nil
45
+ results[k] = public_send(v)
46
+ rescue
47
+ nil
36
48
  end
37
49
  end
38
50
  end
39
51
 
40
- class << self
52
+ class_methods do
41
53
  def default_app_name
42
54
  Moromi::RequestHeader.config.app_name
43
55
  end
@@ -54,6 +66,7 @@ module Moromi
54
66
  bundle_identifier: "X-#{app_class_name}-Bundle-Identifier",
55
67
  bundle_version_string: "X-#{app_class_name}-Bundle-Version-String",
56
68
  bundle_version: "X-#{app_class_name}-Bundle-Version",
69
+ platform: "X-#{app_class_name}-Platform", # ios, android, web, etc
57
70
  os: "X-#{app_class_name}-Os",
58
71
  os_version: "X-#{app_class_name}-Os-Version",
59
72
  device_model: "X-#{app_class_name}-Device-Model",
@@ -67,10 +80,18 @@ module Moromi
67
80
  def create(app_name: nil, args: {})
68
81
  new(app_name: app_name).tap do |header|
69
82
  PROPERTIES.each do |property|
70
- header.send("#{property.to_s}=", args[property]) rescue nil
83
+ value = args[property] || PROPERTY_DEFAULT_VALUES[property]
84
+ header.public_send("#{property.to_s}=", value)
85
+ rescue
86
+ nil
71
87
  end
72
88
  end
73
89
  end
90
+
91
+ def fetch_header(key, headers, app_name)
92
+ name = header_name(key, app_name: app_name)
93
+ headers[name].presence || headers[key]
94
+ end
74
95
  end
75
96
  end
76
97
  end
@@ -0,0 +1,7 @@
1
+ module Moromi
2
+ module RequestHeader
3
+ class Default
4
+ include Core
5
+ end
6
+ end
7
+ end
@@ -1,5 +1,5 @@
1
1
  module Moromi
2
2
  module RequestHeader
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_dependency "activesupport"
24
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"
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moromi-request_header
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Oishi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-22 00:00:00.000000000 Z
11
+ date: 2021-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -28,44 +28,44 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.13'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.13'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '3.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '3.0'
68
+ version: '0'
69
69
  description: Useful HTTP Header
70
70
  email:
71
71
  - takahiro.oishi@dena.jp
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ".github/workflows/ruby.yml"
76
77
  - ".gitignore"
77
78
  - ".rspec"
78
79
  - Gemfile
@@ -81,10 +82,10 @@ files:
81
82
  - Rakefile
82
83
  - bin/console
83
84
  - bin/setup
84
- - circle.yml
85
85
  - lib/moromi/request_header.rb
86
86
  - lib/moromi/request_header/config.rb
87
- - lib/moromi/request_header/ios.rb
87
+ - lib/moromi/request_header/core.rb
88
+ - lib/moromi/request_header/default.rb
88
89
  - lib/moromi/request_header/version.rb
89
90
  - moromi-request_header.gemspec
90
91
  homepage: https://github.com/moromi/moromi-request_header
@@ -105,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  - !ruby/object:Gem::Version
106
107
  version: '0'
107
108
  requirements: []
108
- rubyforge_project:
109
- rubygems_version: 2.5.2
109
+ rubygems_version: 3.0.3
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Useful HTTP Header
data/circle.yml DELETED
@@ -1,17 +0,0 @@
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}