overcast_api 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0aeee3b9363b3269505b3b8a29a24ec430e032b1
4
+ data.tar.gz: 765bf116791fce778a1d4e679c8539ad2b188f3a
5
+ SHA512:
6
+ metadata.gz: 1a964e38558d9b6fdb65f96639a6782b492777851ae23fd963c5339eb7a9505ecc69f830fed5e3f7e94157211d1b77368fc19d23a77af96babb4b0ef6682341c
7
+ data.tar.gz: 3d59459c70e7e08b73c98366f7c4fe8f6843afe4d702e23288e001b0823cd54c86b8f060f37955556f840fc1c2e6463f0e317a1f2fb7f6005c29fcc0213f9657
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in overcast_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 August
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,41 @@
1
+ # OvercastApi
2
+
3
+ Gem for getting information from the Overcast Network website
4
+
5
+ ## Installation
6
+
7
+ Add this to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'overcast_api', github: 'augustt198/overcast-api'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ First, require `overcast_api` in your file
16
+
17
+ ```ruby
18
+ require 'overcast_api'
19
+ ```
20
+
21
+ Get a player with `OvercastApi.player`
22
+
23
+ ```ruby
24
+ player = OvercastApi.player('monsieurapple')
25
+
26
+ player.kills # => 5604
27
+
28
+ => #<OvercastApi::Player:0x007fd11215a1e0
29
+ @username="MonsieurApple", @status="Seen about 14 hours ago",
30
+ @ranks=[
31
+ #<OvercastApi::Rank:0x007fd11214bb68 @name="Administrator", @color="#FA0">,
32
+ #<OvercastApi::Rank:0x007fd11214af38 @name="Developer", @color="purple">
33
+ ],
34
+ @kills=5604, @deaths=4131,
35
+ @friend_count=182,
36
+ @kd_ratio=1.357,
37
+ @kk_ratio=1.728,
38
+ @server_joins=8553,
39
+ @days_played=9.24,
40
+ @raindrops=29100>
41
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,198 @@
1
+ require 'overcast_api/version'
2
+ require 'httparty'
3
+ require 'nokogiri'
4
+
5
+ module OvercastAPI
6
+
7
+ BASE_URL = 'http://oc.tc'
8
+
9
+ # Remove <html> & <body>
10
+ def self.enter_container(base_node)
11
+ base_node.xpath "/html/body/div[@class='container']"
12
+ end
13
+
14
+ def self.player(username)
15
+ resp = HTTParty.get("#{BASE_URL}/#{username}")
16
+ html = Nokogiri::HTML resp.parsed_response
17
+ Player.new(enter_container(html))
18
+ end
19
+
20
+ def self.clean(str)
21
+ str.gsub "\n", ''
22
+ end
23
+
24
+ class Player
25
+ attr_reader :username
26
+ attr_reader :status
27
+ attr_reader :ranks
28
+ attr_reader :name_color
29
+ attr_reader :kills
30
+ attr_reader :deaths
31
+ attr_reader :friend_count
32
+ attr_reader :kd_ration
33
+ attr_reader :kk_ratio
34
+ attr_reader :server_joins
35
+ attr_reader :days_played
36
+ attr_reader :raindrops
37
+ attr_reader :monuments
38
+ attr_reader :contacts
39
+ attr_reader :contact_links
40
+ attr_reader :info
41
+ attr_reader :bio
42
+ attr_reader :trophies
43
+ attr_reader :pvp_encounters
44
+ attr_reader :infractions
45
+
46
+ def initialize(container)
47
+ header = container.xpath "section/div[@class='page-header']"
48
+ @username = header.xpath('h1/span').text
49
+ @username.gsub! "\n", ''
50
+ @status = header.xpath('h1/small').text
51
+ @status.gsub! "\n", ''
52
+
53
+ row = container.xpath "section/div[@class='row']"
54
+
55
+ @ranks = []
56
+ ranks_container = row.xpath "div[@class='span7']/div[@class='row-fluid']/div[@class='span8']/div[@class='row-fluid']/div[@class='span7']/div/span"
57
+ ranks_container.each do |rank_node|
58
+ name = rank_node.text
59
+ color = rank_node['style'].gsub(' ', '').split(';')[0].split(':')[1]
60
+ @ranks << Rank.new(name, color)
61
+ end
62
+
63
+ @kills = row.xpath("div[@class='span7']/div[@class='row-fluid']/div[@class='span8']/div[@class='row-fluid']/div[@class='span5']/h2").text
64
+ @kills = @kills.gsub!("\n", '').to_i
65
+
66
+ @deaths = row.xpath("div[@class='span7']/div[@class='row-fluid']/div[@class='span4']/h2").text
67
+ @deaths = @deaths.gsub!("\n", '').to_i
68
+
69
+ #puts row.xpath("div[@class='span2']/h2")
70
+ @friend_count = row.xpath("div[@class='span2']/h2")[0].text
71
+ @friend_count = @friend_count.gsub!("\n", '').to_i
72
+
73
+ stats_list = row.xpath("div[@class='span3']/h2")
74
+
75
+ @kd_ratio = stats_list[0].text.gsub!("\n", '').to_f
76
+ @kk_ratio = stats_list[1].text.gsub!("\n", '').to_f
77
+ @server_joins = stats_list[2].text.gsub!("\n", '').to_i
78
+ @days_played = stats_list[3].text.gsub!("\n", '').to_f
79
+ @raindrops = stats_list[4].text.gsub!("\n", '')
80
+ k = @raindrops.include? 'k'
81
+ @raindrops = @raindrops.to_f
82
+ @raindrops *= 1000 if k
83
+ @raindrops = @raindrops.to_i
84
+
85
+ info_tabs = container.xpath "section[2]/div[@class='row']/div[@class='span12']/div[@class='tabbable']/div[@class='tab-content']"
86
+
87
+ about = info_tabs.xpath "div[@id='about']"
88
+ contacts = about.xpath "div[1][@class='row']/div[@class='span4']"
89
+ @contacts = {}
90
+ @contact_links = {}
91
+ contacts.each do |contact|
92
+ key = contact.xpath("h6").text
93
+ if key == 'Team'
94
+ value = contact.xpath("blockquote/a").text
95
+ link = BASE_URL + contact.xpath("blockquote/a")[0]['href']
96
+ else
97
+ value = contact.xpath("blockquote/p/a").text
98
+ link = contact.xpath("blockquote/p/a")[0]['href']
99
+ end
100
+ @contacts[key] = value
101
+ @contact_links[key] = link
102
+ end
103
+
104
+ description = about.xpath "div[2][@class='row']/div[@class='span6']"
105
+ @info = {}
106
+ description.each do |info|
107
+ key = info.xpath("h6").text
108
+ value = info.xpath("pre").text
109
+ @info[key] = value
110
+ end
111
+
112
+ @bio = about.xpath("div[3][@class='row']/div[@class='span12']/pre").text
113
+
114
+ trophy_case = info_tabs.xpath "div[@id='trophycase']/div/div/ul/li"
115
+ @trophies = []
116
+ trophy_case.each do |trophy|
117
+ div = trophy.xpath('div')[0]
118
+ description = div['title']
119
+ name = div.xpath('h4').text
120
+ icon = div.xpath('div/i')[0]['class']
121
+ trophies << Trophy.new(name, description, icon)
122
+ end
123
+
124
+ pvp_encounters = info_tabs.xpath "div[@id='pvp-encounters']/div/div[@class='span6']"
125
+ @pvp_encounters = []
126
+ pvp_encounters.each do |col|
127
+ col.xpath('p').each do |encounter|
128
+ parts = encounter.xpath('a')
129
+ killer = parts[0].children[0]['title']
130
+ victim = parts[1].children[0]['title']
131
+ map = parts[2].text
132
+ time = parts[3]['title']
133
+ @pvp_encounters << PvPEncounter.new(killer, victim, map, time)
134
+ end
135
+ end
136
+
137
+ infractions_table = info_tabs.xpath "div[@id='infractions']/div/div/table/tbody/tr"
138
+ @infractions = []
139
+ infractions_table.each do |inf|
140
+ slots = inf.children # <td>
141
+ # @infractions << Infraction.new(punisher, punished, reason, type, expires, date)
142
+ end
143
+
144
+ end
145
+
146
+ end
147
+
148
+ class Rank
149
+ attr_reader :name
150
+ attr_reader :color
151
+ def initialize(name, color)
152
+ @name = name
153
+ @color = color
154
+ end
155
+ end
156
+
157
+ class Trophy
158
+ attr_reader :name
159
+ attr_reader :description
160
+ attr_reader :icon # The FontAwesome icon
161
+ def initialize(name, description, icon)
162
+ @name = name
163
+ @description = description
164
+ @icon = icon
165
+ end
166
+ end
167
+
168
+ class PvPEncounter
169
+ attr_reader :killer
170
+ attr_reader :victim
171
+ attr_reader :map
172
+ attr_reader :time
173
+ def initialize(killer, victim, map, time)
174
+ @killer = killer
175
+ @victim = victim
176
+ @map = map
177
+ @time = time
178
+ end
179
+ end
180
+
181
+ class Infraction
182
+ attr_reader :punisher
183
+ attr_reader :punished
184
+ attr_reader :reason
185
+ attr_reader :type
186
+ attr_reader :expires
187
+ attr_reader :date
188
+ def initialize(punisher, punished, reason, type, expires, date)
189
+ @punisher = punisher
190
+ @punished = punished
191
+ @reason = reason
192
+ @type = type
193
+ @expires = expires
194
+ @date = date
195
+ end
196
+ end
197
+
198
+ end
@@ -0,0 +1,3 @@
1
+ module OvercastAPI
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'overcast_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "overcast_api"
8
+ spec.version = OvercastAPI::VERSION
9
+ spec.authors = ["August"]
10
+ spec.email = ["augustt198@gmail.com"]
11
+ spec.description = %q{RubyGem for retrieving information from the Overcast Network website}
12
+ spec.summary = %q{Ruby wrapper for the Overcast Network Website}
13
+ spec.homepage = "https://github.com/augustt198/overcast-api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency 'rake', '~> 0'
23
+ spec.add_dependency 'httparty', '~> 0.13', '>= 0.13.1'
24
+ spec.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.2.1'
25
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: overcast_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - August
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-13 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.13'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.13.1
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0.13'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.13.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: nokogiri
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.6'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.6.2.1
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.6'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.6.2.1
81
+ description: RubyGem for retrieving information from the Overcast Network website
82
+ email:
83
+ - augustt198@gmail.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - ".gitignore"
89
+ - Gemfile
90
+ - LICENSE.txt
91
+ - README.md
92
+ - Rakefile
93
+ - lib/overcast_api.rb
94
+ - lib/overcast_api/version.rb
95
+ - overcast_api.gemspec
96
+ homepage: https://github.com/augustt198/overcast-api
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.2.0.rc.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Ruby wrapper for the Overcast Network Website
120
+ test_files: []