gw2 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ require "net/https"
2
+ require "json"
3
+ require "gw2/event"
4
+ require "gw2/wvw"
5
+ require "gw2/item"
6
+ require "gw2/recipe"
7
+
8
+ module GW2
9
+ BASE_URL = "https://api.guildwars2.com/v1"
10
+
11
+ def request(attr = { action: "Get" })
12
+ uri = URI.parse(attr[:url])
13
+
14
+ http = Net::HTTP.new(uri.host, uri.port)
15
+ http.use_ssl = attr[:ssl]
16
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if attr[:ssl] # need to get a cert -_____-
17
+
18
+ net_http = Net::HTTP
19
+ request = net_http.const_get(attr[:action]).new(uri.request_uri)
20
+ attr[:headers].each { |key, value| request[key.to_s] = value } if attr[:headers]
21
+
22
+ request.set_form_data(attr[:form_data]) if attr[:form_data]
23
+
24
+ http.request(request)
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ require "gw2/event/event_names"
2
+ require "gw2/event/map_names"
3
+ require "gw2/event/world_names"
4
+ require "gw2/event/events"
5
+
6
+ module GW2
7
+ module Event
8
+ extend GW2
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module Event
3
+ def self.event_names
4
+ response = request(
5
+ action: "Get",
6
+ ssl: true,
7
+ url: "#{BASE_URL}/event_names.json"
8
+ )
9
+
10
+ return JSON.parse(response.body)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ module GW2
2
+ module Event
3
+ PARAMS_FILTER = [:world_id, :map_id, :event_id]
4
+
5
+ def self.all
6
+ self.where
7
+ end
8
+
9
+ def self.where(query_params = {})
10
+ url = "#{BASE_URL}/events.json"
11
+ query_string = query_params.select{ |k,v| PARAMS_FILTER.include?(k) }.collect{ |k,v| "#{k}=#{v}" }.join("&")
12
+ url += "?#{query_string}" unless query_string.empty?
13
+
14
+ response = request(
15
+ action: "Get",
16
+ ssl: true,
17
+ url: url
18
+ )
19
+
20
+ return JSON.parse(response.body)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module Event
3
+ def self.map_names
4
+ response = request(
5
+ action: "Get",
6
+ ssl: true,
7
+ url: "#{BASE_URL}/map_names.json"
8
+ )
9
+
10
+ return JSON.parse(response.body)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module Event
3
+ def self.world_names
4
+ response = request(
5
+ action: "Get",
6
+ ssl: true,
7
+ url: "#{BASE_URL}/world_names.json"
8
+ )
9
+
10
+ return JSON.parse(response.body)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ require "gw2/item/items"
2
+ require "gw2/item/item_details"
3
+
4
+ module GW2
5
+ module Item
6
+ extend GW2
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module Item
3
+ def self.details(item_id)
4
+ response = request(
5
+ action: "Get",
6
+ ssl: true,
7
+ url: "#{BASE_URL}/item_details.json?item_id=#{item_id}"
8
+ )
9
+
10
+ return JSON.parse(response.body)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module Item
3
+ def self.all
4
+ response = request(
5
+ action: "Get",
6
+ ssl: true,
7
+ url: "#{BASE_URL}/items.json"
8
+ )
9
+
10
+ return JSON.parse(response.body)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ require "gw2/recipe/recipes"
2
+ require "gw2/recipe/recipe_details"
3
+
4
+ module GW2
5
+ module Recipe
6
+ extend GW2
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module Recipe
3
+ def self.details(recipe_id)
4
+ response = request(
5
+ action: "Get",
6
+ ssl: true,
7
+ url: "#{BASE_URL}/recipe_details.json?recipe_id=#{recipe_id}"
8
+ )
9
+
10
+ return JSON.parse(response.body)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module Recipe
3
+ def self.all
4
+ response = request(
5
+ action: "Get",
6
+ ssl: true,
7
+ url: "#{BASE_URL}/recipes.json"
8
+ )
9
+
10
+ return JSON.parse(response.body)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require "gw2/wvw/matches"
2
+ require "gw2/wvw/match_details"
3
+ require "gw2/wvw/objective_names"
4
+
5
+ module GW2
6
+ module WvW
7
+ extend GW2
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module WvW
3
+ def self.match_details(match_id)
4
+ response = request(
5
+ action: "Get",
6
+ ssl: true,
7
+ url: "#{BASE_URL}/wvw/match_details.json?match_id=#{match_id}"
8
+ )
9
+
10
+ return JSON.parse(response.body)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module WvW
3
+ def self.matches
4
+ response = request(
5
+ action: "Get",
6
+ ssl: true,
7
+ url: "#{BASE_URL}/wvw/matches.json"
8
+ )
9
+
10
+ return JSON.parse(response.body)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module GW2
2
+ module WvW
3
+ def self.objective_names
4
+ response = request(
5
+ action: "Get",
6
+ ssl: true,
7
+ url: "#{BASE_URL}/wvw/objective_names.json"
8
+ )
9
+
10
+ return JSON.parse(response.body)
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gw2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chris Rosario
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-22 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A ruby gem for accessing the Guild Wars 2 API
15
+ email: c.allen.rosario@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/gw2.rb
21
+ - lib/gw2/event.rb
22
+ - lib/gw2/event/events.rb
23
+ - lib/gw2/event/event_names.rb
24
+ - lib/gw2/event/map_names.rb
25
+ - lib/gw2/event/world_names.rb
26
+ - lib/gw2/wvw.rb
27
+ - lib/gw2/wvw/matches.rb
28
+ - lib/gw2/wvw/match_details.rb
29
+ - lib/gw2/wvw/objective_names.rb
30
+ - lib/gw2/item.rb
31
+ - lib/gw2/item/items.rb
32
+ - lib/gw2/item/item_details.rb
33
+ - lib/gw2/recipe.rb
34
+ - lib/gw2/recipe/recipes.rb
35
+ - lib/gw2/recipe/recipe_details.rb
36
+ homepage: http://rubygems.org/gems/gw2
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.23
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Guild Wars 2 API
60
+ test_files: []