godville_kit 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9c27965def16332d0f30147863804dd8dc70341d
4
+ data.tar.gz: d2691ac5187e3be0babd1afcba48c92d310f66ba
5
+ SHA512:
6
+ metadata.gz: 67d666fdf8fd2f22044d56775496e40b4766cf4cd2144ec0daba6500e62f125aab9b63d4037d4ce5b9cdd5ab89631408703b9fe539c187707faa24f51d90f9bc
7
+ data.tar.gz: 68a204eea2a2d77b198c1721e941d5a56aeed9650107556885db8d447d4965508233eec93fb699d6f52a2894d98f2950992de508997072da5c62de50f5b35be7
@@ -0,0 +1 @@
1
+ require 'godville_kit/initialize'
@@ -0,0 +1,77 @@
1
+ module GodvilleKit
2
+ class APIRequester
3
+ attr_reader :username,
4
+ :password,
5
+ :hero_guid,
6
+ :pantheons_guid
7
+
8
+ class UnexpectedResponseException < StandardError; end
9
+ class InvalidAuthenticationException < StandardError; end
10
+ class AuthenticationCaptchaException < StandardError; end
11
+
12
+ def initialize(username, password, hero_guid, pantheons_guid)
13
+ @username = username
14
+ @password = password
15
+ @hero_guid = hero_guid
16
+ @pantheons_guid = pantheons_guid
17
+ end
18
+
19
+ def request_hero
20
+ authenticate
21
+ GodvilleKit::Hero.new(request_raw_hero_data, request_raw_pantheons_data)
22
+ end
23
+
24
+ def authenticate
25
+ return if authenticated?
26
+
27
+ RestClient.post(
28
+ 'https://godvillegame.com/login/login',
29
+ { username: @username,
30
+ password: @password },
31
+ content_type: :json, accept: :json
32
+ )do |response, request, result, &block|
33
+ case response.code
34
+ when 302
35
+ @cookies = response.cookies
36
+ when 200
37
+ if response.to_s.include? 'captcha'
38
+ raise AuthenticationCaptchaException, 'Too many failed logins, manual login required due to captcha'
39
+ else
40
+ raise InvalidAuthenticationException, 'Invalid Username/Password'
41
+ end
42
+ else
43
+ raise UnexpectedResponseCodeException, "Unexpected response code #{response.code}"
44
+ end
45
+ end
46
+ rescue => e
47
+ @cookies = nil
48
+ puts e.message
49
+ end
50
+
51
+ def authenticated?
52
+ !@cookies.nil?
53
+ end
54
+
55
+ # Request the raw hero data from godville
56
+ def request_raw_hero_data
57
+ return unless authenticated?
58
+
59
+ response = RestClient.get(
60
+ "https://godvillegame.com/fbh/feed?a=#{@hero_guid}",
61
+ cookies: @cookies, content_type: :json, accept: :json
62
+ )
63
+ JSON.parse(response)
64
+ end
65
+
66
+ # Request the raw pantheons data from godville
67
+ def request_raw_pantheons_data
68
+ return unless authenticated?
69
+
70
+ response = RestClient.get(
71
+ "https://godvillegame.com/fbh/feed?a=#{@pantheons_guid}",
72
+ cookies: @cookies, content_type: :json, accept: :json
73
+ )
74
+ JSON.parse(response)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,11 @@
1
+ module GodvilleKit
2
+ class DiaryEntry
3
+ attr_reader :message,
4
+ :time
5
+
6
+ def initialize(raw_diary_entry_data)
7
+ @message = raw_diary_entry_data['msg'].to_s
8
+ @time = raw_diary_entry_data['time'].to_s
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module GodvilleKit
2
+ class Equipment
3
+ attr_reader :weapon,
4
+ :shield,
5
+ :head,
6
+ :body,
7
+ :arms,
8
+ :legs,
9
+ :tailsman
10
+
11
+ def initialize(raw_equipment_data)
12
+ @weapon = GodvilleKit::Gear.new(raw_equipment_data['weapon'])
13
+ @shield = GodvilleKit::Gear.new(raw_equipment_data['shield'])
14
+ @head = GodvilleKit::Gear.new(raw_equipment_data['head'])
15
+ @body = GodvilleKit::Gear.new(raw_equipment_data['body'])
16
+ @arms = GodvilleKit::Gear.new(raw_equipment_data['arms'])
17
+ @legs = GodvilleKit::Gear.new(raw_equipment_data['legs'])
18
+ @talisman = GodvilleKit::Gear.new(raw_equipment_data['talisman'])
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ module GodvilleKit
2
+ class Gear
3
+ attr_reader :name,
4
+ :level
5
+
6
+ def initialize(raw_gear_data)
7
+ @name = raw_gear_data['name'].to_s
8
+ @level = raw_gear_data['level'].to_s
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,106 @@
1
+ module GodvilleKit
2
+ class Hero
3
+ attr_reader :name,
4
+ :god_name,
5
+ :level,
6
+ :quest,
7
+ :quest_progress,
8
+ :exp_progress,
9
+ :health,
10
+ :max_health,
11
+ :alignment,
12
+ :motto,
13
+ :guild,
14
+ :guild_rank,
15
+ :ark,
16
+ :temple_completed_at,
17
+ :ark_completed_at,
18
+ :town,
19
+ :next_town,
20
+ :distance,
21
+ :bricks,
22
+ :wood,
23
+ :god_power,
24
+ :gold,
25
+ :monsters_killed,
26
+ :deaths,
27
+ :arena_wins,
28
+ :arena_losses,
29
+ :approximate_age,
30
+ :birthday,
31
+ :accumulator,
32
+ :quests_completed,
33
+ :monster_name,
34
+ :monster_progress,
35
+ :aura_name,
36
+ :aura_time,
37
+ :max_inventory,
38
+ :inventory,
39
+ :pantheons,
40
+ :equipment,
41
+ :skills,
42
+ :diary
43
+
44
+ def initialize(raw_hero_data, raw_pantheons_data)
45
+ if raw_hero_data
46
+ @name = raw_hero_data['hero']['name'].to_s
47
+ @god_name = raw_hero_data['hero']['godname'].to_s
48
+ @level = raw_hero_data['hero']['level'].to_s
49
+ @quest = raw_hero_data['hero']['quest'].to_s
50
+ @quest_progress = raw_hero_data['hero']['quest_progress'].to_s
51
+ @exp_progress = raw_hero_data['hero']['exp_progress'].to_s
52
+ @health = raw_hero_data['hero']['health'].to_s
53
+ @max_health = raw_hero_data['hero']['max_health'].to_s
54
+ @alignment = raw_hero_data['hero']['alignment'].to_s
55
+ @motto = raw_hero_data['hero']['motto'].to_s
56
+ @guild = raw_hero_data['hero']['clan'].to_s
57
+ @guild_rank = raw_hero_data['hero']['clan_position'].to_s
58
+ @temple_completed_at = raw_hero_data['hero']['temple_completed_at'].to_s
59
+ @ark_completed_at = raw_hero_data['hero']['ark_completed_at'].to_s
60
+ @town = raw_hero_data['hero']['town_name'].to_s
61
+ @next_town = raw_hero_data['hero']['c_town'].to_s
62
+ @distance = raw_hero_data['hero']['distance'].to_s
63
+ @bricks = raw_hero_data['hero']['bricks_cnt'].to_s
64
+ @wood = raw_hero_data['hero']['wood'].to_s
65
+ @god_power = raw_hero_data['hero']['godpower'].to_s
66
+ @gold = raw_hero_data['hero']['gold'].to_s
67
+ @monsters_killed = raw_hero_data['hero']['monsters_killed'].to_s
68
+ @deaths = raw_hero_data['hero']['death_count'].to_s
69
+ @arena_wins = raw_hero_data['hero']['arena_won'].to_s
70
+ @arena_losses = raw_hero_data['hero']['arena_lost'].to_s
71
+ @approximate_age = raw_hero_data['hero']['age_str'].to_s
72
+ @birthday = raw_hero_data['hero']['birthday'].to_s
73
+ @accumulator = raw_hero_data['hero']['accumulator'].to_s
74
+ @quests_completed = raw_hero_data['hero']['quests_completed'].to_s
75
+ @monster_name = raw_hero_data['hero']['monster_name'].to_s
76
+ @monster_progress = raw_hero_data['hero']['monster_progress'].to_s
77
+ @aura_name = raw_hero_data['hero']['aura_name'].to_s
78
+ @aura_time = raw_hero_data['hero']['aura_time'].to_s
79
+ @max_inventory = raw_hero_data['hero']['inventory_max_num'].to_s
80
+
81
+ # Inventory
82
+ @inventory = raw_hero_data['inventory'].keys.map do |key|
83
+ GodvilleKit::Item.new(key, raw_hero_data['inventory'][key].to_s)
84
+ end
85
+
86
+ # Equipment
87
+ @equipment = GodvilleKit::Equipment.new(raw_hero_data['equipment'])
88
+
89
+ # Skils
90
+ @skills = raw_hero_data['skills'].map do |raw_skill_data|
91
+ GodvilleKit::Skill.new(raw_skill_data)
92
+ end
93
+
94
+ # Diary
95
+ @diary = raw_hero_data['diary'].map do |raw_diary_entry_data|
96
+ GodvilleKit::DiaryEntry.new(raw_diary_entry_data)
97
+ end
98
+ end
99
+
100
+ # Pantheons
101
+ if raw_pantheons_data
102
+ @pantheons = GodvilleKit::Pantheons.new(raw_pantheons_data)
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,4 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+
4
+ Dir.glob(File.dirname(__FILE__) + '/**/*.rb') { |file| require file }
@@ -0,0 +1,18 @@
1
+ module GodvilleKit
2
+ class Item
3
+ attr_reader :name,
4
+ :activate_by_use,
5
+ :god_power_required,
6
+ :description,
7
+ :type
8
+
9
+ def initialize(name, raw_item_data)
10
+ @name = name
11
+
12
+ @activate_by_use = raw_item_data['activate_by_user'].to_s
13
+ @god_power_required = raw_item_data['needs_godpower'].to_s
14
+ @description = raw_item_data['description'].to_s
15
+ @type = raw_item_data['type'].to_s
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,47 @@
1
+ module GodvilleKit
2
+ class Pantheons
3
+ attr_reader :gratitude,
4
+ :might,
5
+ :templehood,
6
+ :gladiatorship,
7
+ :storytelling,
8
+ :mastery,
9
+ :construction,
10
+ :taming,
11
+ :survival,
12
+ :savings,
13
+ :creation,
14
+ :destruction,
15
+ :arkeology,
16
+ :unity,
17
+ :popularity,
18
+ :aggressiveness
19
+
20
+ def initialize(raw_pantheons_data)
21
+ pantheon_groups = raw_pantheons_data['groups'].map do |groups|
22
+ groups['pantheons']
23
+ end
24
+
25
+ pantheon_groups.each do |pantheons|
26
+ pantheons.each do |pantheon|
27
+ case pantheon['name'].downcase
28
+ when 'gratitude' then @gratitude = pantheon['position'].to_s
29
+ when 'might' then @might = pantheon['position'].to_s
30
+ when 'templehood' then @templehood = pantheon['position'].to_s
31
+ when 'gladiatorship' then @gladiatorship = pantheon['position'].to_s
32
+ when 'storytelling' then @storytelling = pantheon['position'].to_s
33
+ when 'mastery' then @mastery = pantheon['position'].to_s
34
+ when 'taming' then @taming = pantheon['position'].to_s
35
+ when 'survival' then @survival = pantheon['position'].to_s
36
+ when 'creation' then @creation = pantheon['position'].to_s
37
+ when 'destruction' then @destruction = pantheon['position'].to_s
38
+ when 'arkeology' then @arkeology = pantheon['position'].to_s
39
+ when 'unity' then @unity = pantheon['position'].to_s
40
+ when 'popularity' then @popularity = pantheon['position'].to_s
41
+ when 'aggressiveness' then @aggressiveness = pantheon['position'].to_s
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ module GodvilleKit
2
+ class Skill
3
+ attr_reader :name,
4
+ :level,
5
+ :type
6
+
7
+ def initialize(raw_skill_data)
8
+ @name = raw_skill_data['name'].to_s
9
+ @level = raw_skill_data['level'].to_s
10
+ @type = raw_skill_data['type'].to_s
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module GodvilleKit
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'APIRequester' do
4
+ subject { GodvilleKit::APIRequester.new(nil, nil, nil, nil) }
5
+
6
+ describe '#request_raw_hero_data' do
7
+ context 'when authenticated' do
8
+ it 'returns json' do
9
+ allow(subject).to receive(:authenticated?) { true }
10
+ allow(RestClient).to receive(:get) { fixture_contents('raw_hero_data.json') }
11
+ expect(subject.request_raw_hero_data).to be_a(Hash)
12
+ end
13
+ end
14
+
15
+ context 'when not authenticated' do
16
+ it 'returns nil' do
17
+ allow(subject).to receive(:authenticated?) { false }
18
+ allow(RestClient).to receive(:get) { fixture_contents('raw_hero_data.json') }
19
+ expect(subject.request_raw_hero_data).to be_nil
20
+ end
21
+ end
22
+ end
23
+
24
+ describe '#request_raw_pantheons_data' do
25
+ context 'when authenticated' do
26
+ it 'returns json' do
27
+ allow(subject).to receive(:authenticated?) { true }
28
+ allow(RestClient).to receive(:get) { fixture_contents('raw_pantheons_data.json') }
29
+ expect(subject.request_raw_pantheons_data).to be_a(Hash)
30
+ end
31
+ end
32
+
33
+ context 'when not authenticated' do
34
+ it 'returns nil' do
35
+ allow(subject).to receive(:authenticated?) { false }
36
+ allow(RestClient).to receive(:get) { fixture_contents('raw_pantheons_data.json') }
37
+ expect(subject.request_raw_pantheons_data).to be_nil
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '#request_hero' do
43
+ before do
44
+ allow(subject).to receive(:authenticate)
45
+ allow(subject).to receive(:request_raw_hero_data)
46
+ allow(subject).to receive(:request_raw_pantheons_data)
47
+ end
48
+
49
+ it 'returns valid hero object' do
50
+ expect(subject.request_hero).to be_a(GodvilleKit::Hero)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Hero' do
4
+ subject { GodvilleKit::Hero.new(raw_hero_data, raw_pantheons_data) }
5
+
6
+ let(:raw_hero_data) { JSON.parse(fixture_contents('raw_hero_data.json')) }
7
+ let(:raw_pantheons_data) { JSON.parse(fixture_contents('raw_pantheons_data.json')) }
8
+
9
+ describe '#new' do
10
+ it { should be_a(GodvilleKit::Hero) }
11
+ its(:equipment) { should be_a(GodvilleKit::Equipment) }
12
+ its('equipment.weapon') { should be_a(GodvilleKit::Gear) }
13
+ its('inventory.first') { should be_a(GodvilleKit::Item) }
14
+ its('skills.first') { should be_a(GodvilleKit::Skill) }
15
+ its('diary.first') { should be_a(GodvilleKit::DiaryEntry) }
16
+
17
+ context 'with no raw_hero_data' do
18
+ let(:raw_hero_data) { nil }
19
+
20
+ its(:pantheons) { should be_a(GodvilleKit::Pantheons) }
21
+ its(:equipment) { should be_nil }
22
+ its('inventory') { should be_nil }
23
+ its('skills') { should be_nil }
24
+ its('diary') { should be_nil }
25
+ end
26
+
27
+ context 'with no raw_pantheons_data' do
28
+ let(:raw_pantheons_data) { nil }
29
+
30
+ its(:pantheons) { should be_nil }
31
+ its(:equipment) { should be_a(GodvilleKit::Equipment) }
32
+ its('equipment.weapon') { should be_a(GodvilleKit::Gear) }
33
+ its('inventory.first') { should be_a(GodvilleKit::Item) }
34
+ its('skills.first') { should be_a(GodvilleKit::Skill) }
35
+ its('diary.first') { should be_a(GodvilleKit::DiaryEntry) }
36
+ end
37
+
38
+ context 'with no raw_hero_data and raw_pantheons_data' do
39
+ let(:raw_hero_data) { nil }
40
+ let(:raw_pantheons_data) { nil }
41
+
42
+ its(:pantheons) { should be_nil }
43
+ its(:equipment) { should be_nil }
44
+ its('inventory') { should be_nil }
45
+ its('skills') { should be_nil }
46
+ its('diary') { should be_nil }
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Pantheons' do
4
+ subject { GodvilleKit::Pantheons.new(raw_pantheons_data) }
5
+
6
+ let(:raw_pantheons_data) { JSON.parse(fixture_contents('raw_pantheons_data.json')) }
7
+
8
+ describe '#new' do
9
+ it { should be_a(GodvilleKit::Pantheons) }
10
+ its(:gratitude) { should eq('−') }
11
+ its(:might) { should eq('−') }
12
+ its(:templehood) { should eq('−') }
13
+ its(:gladiatorship) { should eq('−') }
14
+ its(:storytelling) { should eq('−') }
15
+ its(:mastery) { should eq('12269') }
16
+ its(:taming) { should eq('−') }
17
+ its(:survival) { should eq('2607') }
18
+ its(:creation) { should eq('163') }
19
+ its(:destruction) { should eq('−') }
20
+ its(:arkeology) { should eq('−') }
21
+ its(:unity) { should eq('2') }
22
+ its(:popularity) { should eq('4') }
23
+ its(:aggressiveness) { should eq('2') }
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: godville_kit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Jalbert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem kit to instantiate your hero's state from Godville
14
+ email:
15
+ - kevin.j.jalbert@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/godville_kit.rb
21
+ - lib/godville_kit/api_requester.rb
22
+ - lib/godville_kit/diary_entry.rb
23
+ - lib/godville_kit/equipment.rb
24
+ - lib/godville_kit/gear.rb
25
+ - lib/godville_kit/hero.rb
26
+ - lib/godville_kit/initialize.rb
27
+ - lib/godville_kit/item.rb
28
+ - lib/godville_kit/pantheons.rb
29
+ - lib/godville_kit/skill.rb
30
+ - lib/godville_kit/version.rb
31
+ - spec/godville_kit/api_requester_spec.rb
32
+ - spec/godville_kit/hero_spec.rb
33
+ - spec/godville_kit/pantheons_spec.rb
34
+ homepage: https://github.com/kevinjalbert/godville_kit
35
+ licenses: []
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.9.3
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.2.2
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: A gem kit to instantiate your hero's state from Godville
57
+ test_files:
58
+ - spec/godville_kit/api_requester_spec.rb
59
+ - spec/godville_kit/hero_spec.rb
60
+ - spec/godville_kit/pantheons_spec.rb