mobilapp_useragent 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4593815c351791ea7e7e0b52271ad5d6ca4f175f
4
+ data.tar.gz: 6c31db396fe769f3f4ee20cd8e4a542b54c49dec
5
+ SHA512:
6
+ metadata.gz: 562097c1913e58f84de8118ee9939e8f111a4ca2eaa361df95e82290588b0d7081e769f1ac55c3665c8958f305167e84967eae5a0e93e64fc5c058718bc3b100
7
+ data.tar.gz: 5a73e484314fd08f50703b5fce29e75fff7aeda74e01308a574bc10c2ecdc51d413c2511fc2605b50d07cf7789c477d0ee1c6e65430781e451a292d39711580c
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .idea
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mobilapp_useragent.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Emmanuel Lemoine
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # MobilappUseragent
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mobilapp_useragent'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mobilapp_useragent
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/mobilapp_useragent/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,74 @@
1
+ require 'mobilapp_useragent/agent/client'
2
+ require 'mobilapp_useragent/agent/os'
3
+ require 'mobilapp_useragent/agent/device'
4
+ require 'mobilapp_useragent/version'
5
+
6
+ class MobilappUseragent
7
+
8
+ attr_reader :client, :os, :device
9
+
10
+ MATCHER = %r{
11
+ ^([^/\s]*) # Client name
12
+ /([^\s]*) # Client version
13
+ (\s\(([^()]*|\([^()]*\)*)\))? # Comments
14
+ }x.freeze
15
+
16
+ def self.parse(string)
17
+
18
+ if string.nil? || string == ""
19
+ raise ArgumentError, "Expected a value for 'string'"
20
+ end
21
+
22
+ agents = []
23
+
24
+ while m = string.to_s.match(MATCHER)
25
+
26
+ agents << new(m[1], m[2], m[4])
27
+ string = string[m[0].length..-1].strip
28
+
29
+ end
30
+
31
+ agents.first
32
+
33
+ end
34
+
35
+ def initialize(client_name, client_version = nil, comments = nil)
36
+
37
+ if client_name
38
+ @client = Agent::Client.new client_name.downcase, client_version
39
+ else
40
+ raise ArgumentError, "expected a value for @client"
41
+ end
42
+
43
+ parse_comments comments
44
+
45
+ end
46
+
47
+ private
48
+
49
+ def parse_comments comments
50
+
51
+ os = comments.to_s.match(/#{Agent::Os::OS.join('|')}/i)
52
+
53
+ # Set OS from comments
54
+ if os.nil?
55
+
56
+ @os = Agent::Os.new nil, nil
57
+
58
+ else
59
+
60
+ os_version = comments.to_s.match(/(#{os})\s+?((?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+))/i)
61
+ @os = Agent::Os.new os[0].downcase, os_version[2]
62
+
63
+
64
+ @device = Agent::Device.new( @os.name, comments )
65
+
66
+ end
67
+
68
+
69
+
70
+ end
71
+
72
+ end
73
+
74
+
@@ -0,0 +1,20 @@
1
+ class MobilappUseragent
2
+
3
+ module Agent
4
+
5
+ class Client
6
+
7
+ attr_reader :name, :version
8
+
9
+ def initialize(name, version = nil)
10
+
11
+ @name = name
12
+ @version = version
13
+
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,33 @@
1
+ class MobilappUseragent
2
+
3
+ module Agent
4
+
5
+ class Device
6
+
7
+ attr_reader :name
8
+
9
+ def initialize(os, comments)
10
+
11
+ @name = send("get_#{os.downcase}_device", comments)
12
+
13
+ end
14
+
15
+ private
16
+
17
+ def get_ios_device(comments)
18
+
19
+ comments.split(';').first.strip
20
+
21
+ end
22
+
23
+ def get_android_device(comments)
24
+
25
+ comments.split(';').last.strip
26
+
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,25 @@
1
+ class MobilappUseragent
2
+
3
+ module Agent
4
+
5
+ class Os
6
+
7
+ OS = [
8
+ 'android',
9
+ 'ios'
10
+ ]
11
+
12
+ attr_reader :name, :version
13
+
14
+ def initialize(name, version = nil)
15
+
16
+ @name = name
17
+ @version = version
18
+
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,5 @@
1
+ class MobilappUseragent
2
+
3
+ VERSION = "0.0.3"
4
+
5
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mobilapp_useragent/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mobilapp_useragent"
8
+ spec.version = MobilappUseragent::VERSION
9
+ spec.authors = ["Emmanuel Lemoine"]
10
+ spec.email = ["manu@prettyfuntherapy.com"]
11
+ spec.summary = %q{Mobile application's user agent parser }
12
+ spec.description = %q{This gem is useful for parsing mobile application's user agent. Not mobile browser based webapps, but native application. It parses iOS AFNetworking library user agent and Java/Android RetroFit library user agent.}
13
+ spec.homepage = "http://prettyfuntherapy.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake", "~> 0"
23
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobilapp_useragent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Emmanuel Lemoine
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This gem is useful for parsing mobile application's user agent. Not mobile
42
+ browser based webapps, but native application. It parses iOS AFNetworking library
43
+ user agent and Java/Android RetroFit library user agent.
44
+ email:
45
+ - manu@prettyfuntherapy.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - lib/mobilapp_useragent.rb
56
+ - lib/mobilapp_useragent/agent/client.rb
57
+ - lib/mobilapp_useragent/agent/device.rb
58
+ - lib/mobilapp_useragent/agent/os.rb
59
+ - lib/mobilapp_useragent/version.rb
60
+ - mobilapp_useragent.gemspec
61
+ homepage: http://prettyfuntherapy.com
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Mobile application's user agent parser
85
+ test_files: []