gw2 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,8 @@
1
- 1.0.2
1
+ 1.2.0
2
+ -----
3
+ * Large codebase refactor
4
+
5
+ 1.1.0
2
6
  -----
3
7
  * Added Guilds, Map, and Miscellaneous APIs
4
8
 
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # The Guild Wars 2 API Gem
2
+ [![Code Climate](https://codeclimate.com/github/parix/gw2.png)](https://codeclimate.com/github/parix/gw2)
2
3
 
3
4
  A Ruby interface for accessing the Guild Wars 2 API.
4
5
 
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "gw2"
3
- s.version = "1.1.0"
4
- s.date = "2013-09-28"
3
+ s.version = "1.2.0"
4
+ s.date = "2014-02-05"
5
5
  s.summary = "Guild Wars 2 API"
6
6
  s.description = "A ruby gem for accessing the Guild Wars 2 API"
7
7
  s.authors = ["Chris Rosario"]
data/lib/gw2.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "net/https"
2
- require "json"
1
+ require "gw2/json"
2
+ require "gw2/https"
3
3
  require "gw2/event"
4
4
  require "gw2/wvw"
5
5
  require "gw2/item"
@@ -9,21 +9,5 @@ require "gw2/misc"
9
9
  require "gw2/map"
10
10
 
11
11
  module GW2
12
- BASE_URL = "https://api.guildwars2.com/v1"
13
-
14
- def request(attr = { action: "Get" })
15
- uri = URI.parse(attr[:url])
16
-
17
- http = Net::HTTP.new(uri.host, uri.port)
18
- http.use_ssl = attr[:ssl]
19
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE if attr[:ssl] # need to get a cert -_____-
20
-
21
- net_http = Net::HTTP
22
- request = net_http.const_get(attr[:action]).new(uri.request_uri)
23
- attr[:headers].each { |key, value| request[key.to_s] = value } if attr[:headers]
24
-
25
- request.set_form_data(attr[:form_data]) if attr[:form_data]
26
-
27
- http.request(request)
28
- end
12
+ BASE_URL = "https://api.guildwars2.com/v1"
29
13
  end
@@ -5,6 +5,7 @@ require "gw2/event/events"
5
5
 
6
6
  module GW2
7
7
  module Event
8
- extend GW2
8
+ extend HTTPS
9
+ extend JSON
9
10
  end
10
11
  end
@@ -1,13 +1,7 @@
1
1
  module GW2
2
2
  module Event
3
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)
4
+ parse(request("/event_names.json").body)
11
5
  end
12
6
  end
13
7
  end
@@ -1,23 +1,11 @@
1
1
  module GW2
2
2
  module Event
3
- PARAMS_FILTER = [:world_id, :map_id, :event_id]
4
-
5
3
  def self.all
6
4
  self.where
7
5
  end
8
6
 
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)
7
+ def self.where(query_hash = {})
8
+ parse(request("/events.json", query: query_hash).body)
21
9
  end
22
10
  end
23
11
  end
@@ -1,13 +1,7 @@
1
1
  module GW2
2
2
  module Event
3
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)
4
+ parse(request("/map_names.json").body)
11
5
  end
12
6
  end
13
7
  end
@@ -1,13 +1,7 @@
1
1
  module GW2
2
2
  module Event
3
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)
4
+ parse(request("/world_names.json").body)
11
5
  end
12
6
  end
13
7
  end
@@ -2,6 +2,7 @@ require "gw2/guild/guild_details"
2
2
 
3
3
  module GW2
4
4
  module Guild
5
- extend GW2
5
+ extend HTTPS
6
+ extend JSON
6
7
  end
7
- end
8
+ end
@@ -1,19 +1,7 @@
1
1
  module GW2
2
2
  module Guild
3
- PARAMS_FILTER = [:guild_id, :guild_name]
4
-
5
- def self.details(query_params)
6
- url = "#{BASE_URL}/guild_details.json"
7
- query_string = query_params.select{ |k,v| PARAMS_FILTER.include?(k) }.collect { |k,v| "#{k}=#{v}" }.join("&")
8
- url += "?#{query_string}"
9
-
10
- response = request(
11
- action: "Get",
12
- ssl: true,
13
- url: url
14
- )
15
-
16
- return JSON.parse(response.body)
3
+ def self.details(query_hash = {})
4
+ parse(request("/guild_details.json", query: query_hash).body)
17
5
  end
18
6
  end
19
- end
7
+ end
@@ -0,0 +1,31 @@
1
+ require "net/https"
2
+
3
+ module GW2
4
+ module HTTPS
5
+ DEFAULT_REQUEST = { action: "Get", ssl: true }
6
+
7
+ def query_string(query_hash = {})
8
+ string = query_hash.collect{ |k,v| "#{k}=#{v}" }.join("&")
9
+ string.prepend("?") unless string.empty?
10
+
11
+ string
12
+ end
13
+
14
+ def request(end_point = "", attr = {})
15
+ attr = DEFAULT_REQUEST.merge(attr)
16
+ uri = URI.parse(BASE_URL + end_point + query_string(attr[:query] || {}))
17
+
18
+ http = Net::HTTP.new(uri.host, uri.port)
19
+ http.use_ssl = attr[:ssl]
20
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if attr[:ssl] # need to get a cert -_____-
21
+
22
+ net_http = Net::HTTP
23
+ request = Net::HTTP.const_get(attr[:action]).new(uri.request_uri)
24
+ attr[:headers].each { |key, value| request[key.to_s] = value } if attr[:headers]
25
+
26
+ request.set_form_data(attr[:form_data]) if attr[:form_data]
27
+
28
+ http.request(request)
29
+ end
30
+ end
31
+ end
@@ -3,6 +3,7 @@ require "gw2/item/item_details"
3
3
 
4
4
  module GW2
5
5
  module Item
6
- extend GW2
6
+ extend HTTPS
7
+ extend JSON
7
8
  end
8
9
  end
@@ -1,13 +1,7 @@
1
1
  module GW2
2
- module Item
2
+ module Item
3
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)
4
+ parse(request("/item_details.json", query: { item_id: item_id }).body)
11
5
  end
12
6
  end
13
7
  end
@@ -1,13 +1,7 @@
1
1
  module GW2
2
2
  module Item
3
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)
4
+ parse(request("/items.json").body)
11
5
  end
12
6
  end
13
7
  end
@@ -0,0 +1,9 @@
1
+ require "json"
2
+
3
+ module GW2
4
+ module JSON
5
+ def parse(string)
6
+ ::JSON.parse(string)
7
+ end
8
+ end
9
+ end
@@ -1,9 +1,10 @@
1
- require "gw2/map/continents"
2
- require "gw2/map/maps"
3
- require "gw2/map/map_floor"
4
-
5
- module GW2
6
- module Map
7
- extend GW2
8
- end
9
- end
1
+ require "gw2/map/continents"
2
+ require "gw2/map/maps"
3
+ require "gw2/map/map_floor"
4
+
5
+ module GW2
6
+ module Map
7
+ extend HTTPS
8
+ extend JSON
9
+ end
10
+ end
@@ -1,13 +1,7 @@
1
- module GW2
2
- module Map
3
- def self.continents
4
- response = request(
5
- action: "Get",
6
- ssl: true,
7
- url: "#{BASE_URL}/continents.json"
8
- )
9
-
10
- return JSON.parse(response.body)
11
- end
12
- end
13
- end
1
+ module GW2
2
+ module Map
3
+ def self.continents
4
+ parse(request("/continents.json").body)
5
+ end
6
+ end
7
+ end
@@ -1,13 +1,7 @@
1
- module GW2
2
- module Map
3
- def self.map_floor(continent_id, floor)
4
- response = request(
5
- action: "Get",
6
- ssl: true,
7
- url: "#{BASE_URL}/map_floor.json?continent_id=#{continent_id}&floor=#{floor}"
8
- )
9
-
10
- return JSON.parse(response.body)
11
- end
12
- end
13
- end
1
+ module GW2
2
+ module Map
3
+ def self.map_floor(continent_id, floor)
4
+ parse(request("/map_floor.json", query: { continent_id: continent_id, floor: floor }).body)
5
+ end
6
+ end
7
+ end
@@ -1,21 +1,13 @@
1
- module GW2
2
- module Map
3
- def self.all
4
- self.where
5
- end
6
-
7
- def self.where(map_id = {})
8
- url = "#{BASE_URL}/maps.json"
9
- query_string = map_id.collect { |k,v| "#{v}" }.join
10
- url += "?map_id=#{query_string}" unless query_string.empty?
11
-
12
- response = request(
13
- action: "Get",
14
- ssl: true,
15
- url: url
16
- )
17
-
18
- return JSON.parse(response.body)
19
- end
20
- end
21
- end
1
+ module GW2
2
+ module Map
3
+ PARAMS_FILTER = [:map_id]
4
+
5
+ def self.all
6
+ self.where
7
+ end
8
+
9
+ def self.where(query_hash = {})
10
+ parse(request("/maps.json", query: query_hash).body)
11
+ end
12
+ end
13
+ end
@@ -1,9 +1,10 @@
1
- require "gw2/misc/build"
2
- require "gw2/misc/colors"
3
- require "gw2/misc/files"
4
-
5
- module GW2
6
- module Misc
7
- extend GW2
8
- end
9
- end
1
+ require "gw2/misc/build"
2
+ require "gw2/misc/colors"
3
+ require "gw2/misc/files"
4
+
5
+ module GW2
6
+ module Misc
7
+ extend HTTPS
8
+ extend JSON
9
+ end
10
+ end
@@ -1,14 +1,8 @@
1
- module GW2
2
- module Misc
3
- def self.build
4
- response = request(
5
- action: "Get",
6
- ssl: true,
7
- url: "#{BASE_URL}/build.json"
8
- )
9
-
10
- return JSON.parse(response.body)
11
- end
12
- end
13
- end
14
-
1
+ module GW2
2
+ module Misc
3
+ def self.build
4
+ parse(request("/build.json").body)
5
+ end
6
+ end
7
+ end
8
+
@@ -1,13 +1,7 @@
1
- module GW2
2
- module Misc
3
- def self.colors
4
- response = request(
5
- action: "Get",
6
- ssl: true,
7
- url: "#{BASE_URL}/colors.json"
8
- )
9
-
10
- return JSON.parse(response.body)
11
- end
12
- end
13
- end
1
+ module GW2
2
+ module Misc
3
+ def self.colors
4
+ parse(request("/colors.json").body)
5
+ end
6
+ end
7
+ end
@@ -1,13 +1,7 @@
1
- module GW2
2
- module Misc
3
- def self.files
4
- response = request(
5
- action: "Get",
6
- ssl: true,
7
- url: "#{BASE_URL}/files.json"
8
- )
9
-
10
- return JSON.parse(response.body)
11
- end
12
- end
13
- end
1
+ module GW2
2
+ module Misc
3
+ def self.files
4
+ parse(request("/files.json").body)
5
+ end
6
+ end
7
+ end
@@ -3,6 +3,7 @@ require "gw2/recipe/recipe_details"
3
3
 
4
4
  module GW2
5
5
  module Recipe
6
- extend GW2
6
+ extend HTTPS
7
+ extend JSON
7
8
  end
8
9
  end
@@ -1,13 +1,7 @@
1
1
  module GW2
2
- module Recipe
2
+ module Recipe
3
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)
4
+ parse(request("/recipe_details.json", query: { recipe_id: recipe_id }).body)
11
5
  end
12
6
  end
13
7
  end
@@ -1,13 +1,7 @@
1
1
  module GW2
2
2
  module Recipe
3
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)
4
+ parse(request("/recipes.json").body)
11
5
  end
12
6
  end
13
7
  end
@@ -4,6 +4,7 @@ require "gw2/wvw/objective_names"
4
4
 
5
5
  module GW2
6
6
  module WvW
7
- extend GW2
7
+ extend HTTPS
8
+ extend JSON
8
9
  end
9
10
  end
@@ -1,13 +1,7 @@
1
1
  module GW2
2
2
  module WvW
3
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)
4
+ parse(request("/wvw/match_details.json", query: { match_id: match_id }).body)
11
5
  end
12
6
  end
13
7
  end
@@ -1,13 +1,7 @@
1
1
  module GW2
2
2
  module WvW
3
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)
4
+ parse(request("/wvw/matches.json").body)
11
5
  end
12
6
  end
13
7
  end
@@ -1,13 +1,7 @@
1
1
  module GW2
2
2
  module WvW
3
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)
4
+ parse(request("/wvw/objective_names.json").body)
11
5
  end
12
6
  end
13
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gw2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-28 00:00:00.000000000 Z
12
+ date: 2014-02-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A ruby gem for accessing the Guild Wars 2 API
15
15
  email: c.allen.rosario@gmail.com
@@ -28,9 +28,11 @@ files:
28
28
  - lib/gw2/event.rb
29
29
  - lib/gw2/guild/guild_details.rb
30
30
  - lib/gw2/guild.rb
31
+ - lib/gw2/https.rb
31
32
  - lib/gw2/item/item_details.rb
32
33
  - lib/gw2/item/items.rb
33
34
  - lib/gw2/item.rb
35
+ - lib/gw2/json.rb
34
36
  - lib/gw2/map/continents.rb
35
37
  - lib/gw2/map/map_floor.rb
36
38
  - lib/gw2/map/maps.rb