Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consolidation, refactoring and restructuring #3

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
379fcf6
fix whitespace and line endings
nocash Sep 6, 2014
45af35f
consolidate Item methods
nocash Sep 6, 2014
ab3b8aa
remove redundant describe block
nocash Sep 6, 2014
1bc409d
use describe method for methods. the context is unchanged.
nocash Sep 6, 2014
412d8df
prefix class methods with "." instead of "#"
nocash Sep 6, 2014
b65da50
remove redundant tests
nocash Sep 6, 2014
3989a44
remove unnecessary before blocks
nocash Sep 6, 2014
c9e8a96
add coverage directory to gitignore
nocash Sep 6, 2014
34fe777
sort gitignore for easy scanning
nocash Sep 6, 2014
2e698e8
add directory slashes to gitignore
nocash Sep 6, 2014
a90cc7d
remove non-project-related entry from gitignore
nocash Sep 6, 2014
8a75ea9
add .ruby-gemset to .gitignore
nocash Sep 6, 2014
ccfc219
consolidate remote methods under ApiInterface
nocash Sep 6, 2014
b2274b3
create .get method for api requests
nocash Sep 6, 2014
801cb2d
rename ApiInterface to ApiRequest
nocash Sep 6, 2014
7715288
add pry to gemfile; sort for easy scanning
nocash Sep 7, 2014
857f0a4
remove unused net_http variable
nocash Sep 6, 2014
41eff3e
move/rename item spec
nocash Sep 6, 2014
f6b2968
consolidate class methods and specs
nocash Sep 6, 2014
670f03d
remove unused PARAMS_FILTER constant
nocash Sep 6, 2014
fc8da41
remove redudant calls to self
nocash Sep 6, 2014
c051aba
use ApiRequest.get method in for requests
nocash Sep 6, 2014
50b2943
use array to scope endpoints
nocash Sep 6, 2014
5d6bae4
version bump
nocash Sep 7, 2014
e3fe4d0
use shorter "path" variable
nocash Sep 7, 2014
9af8c3e
remove use of instance variables in events spec
nocash Sep 6, 2014
79dbb20
create #endpoint_uri spec helper
nocash Sep 7, 2014
6be2423
improve test readability with variables
nocash Sep 7, 2014
66932bd
remove status stub; the code doesn't check response status
nocash Sep 7, 2014
b0cba29
use #stub_endpoint and Event struct to improve readability
nocash Sep 7, 2014
3573df7
change #stub_request to return stub result only
nocash Sep 7, 2014
3466819
split guild .details spec into two distinct tests
nocash Sep 7, 2014
7dc001b
use #stub_endpoint and local variables in item spec
nocash Sep 7, 2014
e15036a
refactor remaining specs
nocash Sep 7, 2014
42ae891
use shared example for checking API response parsing
nocash Sep 7, 2014
d6fccf5
simplify request code with OpenURI #read
nocash Sep 8, 2014
5fe4b4e
remove ineffectual "private" declaration
nocash Sep 8, 2014
1171c5a
remove default value for end_point variable
nocash Sep 8, 2014
924066c
update spec sample data
nocash Sep 8, 2014
e500cf4
remove pry from Gemfile
nocash Sep 8, 2014
b5c4246
use hash instead of keyword for backwards compatibility
nocash Sep 8, 2014
af8e53c
use Chauncy's full name in test data
nocash Sep 13, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.gem
.bundle/
.ruby-gemset
.ruby-version
Gemfile.lock
.bundle
vendor
*.gem
.DS_Store
coverage/
vendor/
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "https://rubygems.org"

gem "coveralls", "0.7.0", require: false
gem "rake", "10.1.1"
gem "rspec", "2.14.1"
gem "webmock", "1.15.2"
gem "vcr", "2.8.0"
gem "coveralls", "0.7.0", require: false
gem "webmock", "1.15.2"
4 changes: 2 additions & 2 deletions gw2.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = "gw2"
s.version = "1.2.0"
s.date = "2014-02-05"
s.version = "1.2.1"
s.date = "2014-09-06"
s.summary = "Guild Wars 2 API"
s.description = "A ruby gem for accessing the Guild Wars 2 API"
s.authors = ["Chris Rosario"]
Expand Down
3 changes: 1 addition & 2 deletions lib/gw2.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "gw2/json"
require "gw2/https"
require "gw2/api_request"
require "gw2/event"
require "gw2/wvw"
require "gw2/item"
Expand Down
20 changes: 20 additions & 0 deletions lib/gw2/api_request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "gw2/https"
require "gw2/json"

module GW2
class ApiRequest
extend HTTPS
extend JSON

def self.get(endpoint, query = {})
path = endpoint_path(endpoint)
response = request(path, query: query)
parse(response)
end

def self.endpoint_path(endpoint)
endpoint = Array(endpoint).join('/')
"/#{endpoint}.json"
end
end
end
28 changes: 20 additions & 8 deletions lib/gw2/event.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
require "gw2/event/event_names"
require "gw2/event/map_names"
require "gw2/event/world_names"
require "gw2/event/events"

module GW2
module Event
extend HTTPS
extend JSON
class Event < ApiRequest
def self.all
where
end

def self.where(query_hash = {})
get :events, query_hash
end

def self.event_names
get :event_names
end

def self.map_names
get :map_names
end

def self.world_names
get :world_names
end
end
end
7 changes: 0 additions & 7 deletions lib/gw2/event/event_names.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/gw2/event/events.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/gw2/event/map_names.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/gw2/event/world_names.rb

This file was deleted.

9 changes: 4 additions & 5 deletions lib/gw2/guild.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
require "gw2/guild/guild_details"

module GW2
module Guild
extend HTTPS
extend JSON
class Guild < ApiRequest
def self.details(query_hash = {})
get :guild_details, query_hash
end
end
end
7 changes: 0 additions & 7 deletions lib/gw2/guild/guild_details.rb

This file was deleted.

28 changes: 13 additions & 15 deletions lib/gw2/https.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
require "net/https"
require "open-uri"

module GW2
module HTTPS
DEFAULT_REQUEST = { action: "Get", ssl: true }
DEFAULT_REQUEST = { action: "Get", ssl: true, query: {} }

def endpoint_uri(endpoint, query = {})
URI.parse(BASE_URL + endpoint + query_string(query))
end
module_function :endpoint_uri

def query_string(query_hash = {})
string = query_hash.collect{ |k,v| "#{k}=#{v}" }.join("&")
string.prepend("?") unless string.empty?

string
end
module_function :query_string

def request(end_point = "", attr = {})
attr = DEFAULT_REQUEST.merge(attr)
uri = URI.parse(BASE_URL + end_point + query_string(attr[:query] || {}))

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = attr[:ssl]
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if attr[:ssl] # need to get a cert -_____-

net_http = Net::HTTP
request = Net::HTTP.const_get(attr[:action]).new(uri.request_uri)
attr[:headers].each { |key, value| request[key.to_s] = value } if attr[:headers]
private

request.set_form_data(attr[:form_data]) if attr[:form_data]
def request(end_point, attr = {})
attr = DEFAULT_REQUEST.merge(attr)
uri = endpoint_uri(end_point, attr[:query])

http.request(request)
uri.read
end
end
end
14 changes: 8 additions & 6 deletions lib/gw2/item.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require "gw2/item/items"
require "gw2/item/item_details"

module GW2
module Item
extend HTTPS
extend JSON
class Item < ApiRequest
def self.all
get :items
end

def self.details(item_id)
get :item_details, item_id: item_id
end
end
end
7 changes: 0 additions & 7 deletions lib/gw2/item/item_details.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/gw2/item/items.rb

This file was deleted.

23 changes: 16 additions & 7 deletions lib/gw2/map.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
require "gw2/map/continents"
require "gw2/map/maps"
require "gw2/map/map_floor"

module GW2
module Map
extend HTTPS
extend JSON
class Map < ApiRequest
def self.all
where
end

def self.where(query_hash = {})
get :maps, query_hash
end

def self.map_floor(continent_id, floor)
get :map_floor, continent_id: continent_id, floor: floor
end

def self.continents
get :continents
end
end
end
7 changes: 0 additions & 7 deletions lib/gw2/map/continents.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/gw2/map/map_floor.rb

This file was deleted.

13 changes: 0 additions & 13 deletions lib/gw2/map/maps.rb

This file was deleted.

19 changes: 12 additions & 7 deletions lib/gw2/misc.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
require "gw2/misc/build"
require "gw2/misc/colors"
require "gw2/misc/files"

module GW2
module Misc
extend HTTPS
extend JSON
class Misc < ApiRequest
def self.build
get :build
end

def self.colors
get :colors
end

def self.files
get :files
end
end
end
8 changes: 0 additions & 8 deletions lib/gw2/misc/build.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/gw2/misc/colors.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/gw2/misc/files.rb

This file was deleted.

14 changes: 8 additions & 6 deletions lib/gw2/recipe.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require "gw2/recipe/recipes"
require "gw2/recipe/recipe_details"

module GW2
module Recipe
extend HTTPS
extend JSON
class Recipe < ApiRequest
def self.all
get :recipes
end

def self.details(recipe_id)
get :recipe_details, recipe_id: recipe_id
end
end
end
7 changes: 0 additions & 7 deletions lib/gw2/recipe/recipe_details.rb

This file was deleted.

7 changes: 0 additions & 7 deletions lib/gw2/recipe/recipes.rb

This file was deleted.

19 changes: 12 additions & 7 deletions lib/gw2/wvw.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
require "gw2/wvw/matches"
require "gw2/wvw/match_details"
require "gw2/wvw/objective_names"

module GW2
module WvW
extend HTTPS
extend JSON
class WvW < ApiRequest
def self.matches
get [:wvw, :matches]
end

def self.match_details(match_id)
get [:wvw, :match_details], match_id: match_id
end

def self.objective_names
get [:wvw, :objective_names]
end
end
end
7 changes: 0 additions & 7 deletions lib/gw2/wvw/match_details.rb

This file was deleted.

Loading