lita-destiny 0.1.2 → 0.1.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 273db0f6ec1165b2bfb680c9adb3dbb17784d983
4
- data.tar.gz: 8a77938f5edd415ec959fe837f8f1d853c2b83e3
3
+ metadata.gz: 1001acb2f432e2829d2350b9b135e21ed25e15cb
4
+ data.tar.gz: 408334e7ac7d4c16764329f7eedbb0a68e24b231
5
5
  SHA512:
6
- metadata.gz: 93111e093fb4d5001ad794df9017067859138d5611984921fcf2fbc8fa0be319d80eb2334b639afc6cf1d9692f7d815df084c461f4ccb0d8ec42b3c70b835ff8
7
- data.tar.gz: 88f9029bc6439c23e1fe82f871acd8e9597c5d66eac40d3d8034293263a99642fc5762703bd9cabd2601d8e85636e57c2a9e42a9d26b95f16cdbebf36f871458
6
+ metadata.gz: b891fde418eace9f3d39800c42f9d0e5c6a3bf9eabf2013adc3387e19c4a46d82a0431326a150158aa0e67c56d791d269c250cd56c7b63be129ed853d2839eb6
7
+ data.tar.gz: a492befaf6f8be623437c46105001f3abe2c57f9a361b9c2af74e11926c4e8056426bd38f32b845a3898c3bccff3e708498ab4ed9ff0f1203be0a4d9520c6097
data/Gemfile CHANGED
@@ -1,5 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gemspec
4
-
5
- gem 'httparty'
3
+ gemspec
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # lita-destiny
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/lita-destiny.svg)](http://badge.fury.io/rb/lita-destiny)
3
4
  [![Build Status](https://travis-ci.org/PDaily/lita-destiny.svg?branch=master)](https://travis-ci.org/PDaily/lita-destiny)
5
+ [![Code Climate](https://codeclimate.com/github/PDaily/lita-destiny/badges/gpa.svg)](https://codeclimate.com/github/PDaily/lita-destiny)
4
6
  [![Coverage Status](https://coveralls.io/repos/PDaily/lita-destiny/badge.svg?branch=master)](https://coveralls.io/r/PDaily/lita-destiny?branch=master)
5
7
 
6
8
  Lita handler for interacting with the Destiny API
@@ -1,25 +1,54 @@
1
1
  require 'httparty'
2
2
 
3
+ # DestinyAPI module wrapper
3
4
  module DestinyAPI
5
+ # Base API Class
6
+ #
7
+ # Usage:
8
+ # destiny = DestinyAPI::Base.new(api_token)
9
+ #
4
10
  class Base
11
+ # Include HTTParty Module
5
12
  include HTTParty
13
+ # Auto-parse responses from Bungie as JSON
6
14
  format :json
15
+ # Set base uri
7
16
  base_uri 'www.bungie.net/platform/destiny/'
8
17
 
9
18
 
10
19
  # Init the Destiny API with Bungie API stored in ENV variable
11
- # destiny = Destiny.new(api_token)
20
+ #
21
+ # Usage:
22
+ # destiny = DestinyAPI::Base.new('6971067dec36c6597cd57789a62f48f0')
23
+ #
24
+ # Arguments:
25
+ # api_token: (String)
26
+ #
12
27
  def initialize(api_token)
13
28
  @headers = { 'X-API-Key' => api_token, 'Content-Type' => 'application/json' }
14
29
  end
15
30
 
16
- # Pull the days advisor report from http://www.bungie.net/platform/destiny/advisors/
17
- # destiny.advisors
31
+ # GET the days advisor report from http://www.bungie.net/platform/destiny/advisors/
32
+ #
33
+ # Usage:
34
+ # destiny.advisors
35
+ #
18
36
  def advisors
19
37
  raw_data = self.class.get('/advisors', headers: @headers)
20
38
  parsed = raw_data.parsed_response['Response']['data']
21
39
  end
22
40
 
41
+ # GET the activity information from http://www.bungie.net/platform/destiny/manifest/activity/{activity_hash}/
42
+ #
43
+ # Raw argument will return an unmodified respons from Bungie.
44
+ #
45
+ # Usage:
46
+ # destiny.activity('3508129769', false)
47
+ #
48
+ # Arguments:
49
+ # activity_hash: (String)
50
+ # raw: (Boolean)
51
+ #
23
52
  def activity(activity_hash, raw=false)
24
53
  raw_data = self.class.get("/manifest/activity/#{activity_hash}").parsed_response['Response']['data']['activity']
25
54
  skulls = []
@@ -33,30 +62,38 @@ module DestinyAPI
33
62
  end
34
63
  end
35
64
 
36
- # Pull the weekly nightfall info from http://www.bungie.net/platform/destiny/manifest/activity/#{activity_hash}
37
- # Optional boolean argument, defaults to false from activity method to only return basic information for Lita bot.
65
+ # GET the weekly nightfall info from http://www.bungie.net/platform/destiny/manifest/activity/#{activity_hash}
66
+ #
67
+ # Optional boolean argument.
38
68
  #
39
- # destiny.nightfall
69
+ # Usage:
70
+ # destiny.nightfall(true)
71
+ #
72
+ # Arguments:
73
+ # raw: (boolean)
40
74
  #
41
- def nightfall(options={})
75
+ def nightfall(raw=false)
42
76
  nightfall_activity_hash = self.advisors['nightfallActivityHash']
43
- activity(nightfall_activity_hash, boolean)
77
+ activity(nightfall_activity_hash, raw)
44
78
  end
45
79
 
46
- # Pull the weekly nightfall info from http://www.bungie.net/platform/destiny/manifest/activity/#{activity_hash}
80
+ # GET the weekly nightfall info from http://www.bungie.net/platform/destiny/manifest/activity/#{activity_hash}
47
81
  # Returns an array of three items, only need one for the skulls and location.
48
82
  #
49
83
  # Optional boolean argument, defaults to false from activity method to return basic information for Lita bot.
50
84
  #
51
- # destiny.weekly_strike(false)
85
+ # Usage:
86
+ # destiny.weekly_strike(false)
87
+ #
88
+ # Arguments:
89
+ # raw: (boolean)
52
90
  #
53
- def weekly_strike(options={})
91
+ def weekly_strike(raw=false)
54
92
  heroic_strike_hashes = self.advisors['heroicStrikeHashes']
55
- activity(heroic_strike_hashes[0], boolean)
93
+ activity(heroic_strike_hashes[0], raw)
56
94
  end
57
95
 
58
- # Pull the weekly nightfall info from http://www.bungie.net/platform/destiny/manifest/activity/#{activity_hash}
59
- #
96
+ # GET the weekly nightfall info from http://www.bungie.net/platform/destiny/manifest/activity/#{activity_hash}
60
97
  #
61
98
  # No known endpoints.
62
99
  def arena(options={})
@@ -71,12 +108,28 @@ module DestinyAPI
71
108
  # Pull the days bounties
72
109
  def bounties
73
110
  end
74
-
111
+
112
+ # GET information about a place, specifically a planet.
113
+ #
114
+ # Usage:
115
+ # destiny.place('3747705955')
116
+ #
117
+ # Arguments:
118
+ # place_hash: (String)
119
+ #
75
120
  def place(place_hash)
76
121
  raw data = self.class.get('/manifest/place/#{place_hash}').parsed_response['Response']['data']['place']
77
122
  response = { place_name: raw_data['placeName'], place_desc: raw_data['placeDescription'] }
78
123
  end
79
124
 
125
+ # GET information about a destination, specifically a location on a planet.
126
+ #
127
+ # Usage:
128
+ # destiny.destination('518553403')
129
+ #
130
+ # Arguments:
131
+ # destination_hash: (String)
132
+ #
80
133
  def destination(destination_hash)
81
134
  raw_data = self.class.get('/manifest/destination/#{destination_hash}').parsed_response['Response']['data']
82
135
  response = { dest_name: raw_data['destinationName'], dest_desc: raw_data['destinationDescription'] }
@@ -1,37 +1,103 @@
1
1
  module Lita
2
2
  module Handlers
3
- class Destiny < Handler
4
- namespace "destiny"
5
- # Bring in DestinyAPI module
6
- include DestinyAPI
7
-
3
+ class Destiny < Handler
8
4
  # Required configuration attribute
9
- config :api_key, type: String, required: true do
5
+ config :api_key, type: String, required: true do
6
+ # Do validation against provided api_key, MUST be 32 chars.
10
7
  validate do |value|
8
+ # Raise error unless api_key is 32 chars.
11
9
  "must be 32 characters" unless value.respond_to?(:size) && value.size == 32
12
10
  end
13
11
  end
14
12
 
15
-
16
- # Set up our client
17
- destiny_client = DestinyAPI::Base.new(config.api_key).call
13
+ # Bring in DestinyAPI module
14
+ include DestinyAPI
18
15
 
16
+ # Nightfall Route
17
+ route(/^!(nightfall)/i, :nightfall , help: { "!nightfall" => "Get this weeks nightfall description and skulls" })
19
18
 
20
- route(/^!\w(.*)/i, :nightfall , help: { "!nightfall" => "Get this weeks nightfall description and skulls" })
19
+ # Weekly Strike Route
20
+ route(/^!(weekly)/i, :weekly , help: { "!weekly" => "Get this weeks nightfall description and skulls" })
21
21
 
22
-
22
+ # Xur Route
23
+ route(/^!(xur)/i, :xur , help: { "!xur" => "Get Xur's inventory when availible" })
24
+
25
+ # Nightfall Activity Method
26
+ #
27
+ # Calls #build_activity_message(activity)
28
+ # where activity would be nightfall.
29
+ #
23
30
  def nightfall(response)
31
+ # Set up our client
32
+ destiny_client = DestinyAPI::Base.new(api_key)
33
+ # Build the activity message with nightfall info
24
34
  build_activity_message(destiny_client.nightfall, response)
25
35
  end
26
36
 
27
- # activity = { activityName: raw_data['activityName'], activityDescription: raw_data['activityDescription'], skulls: skulls }
37
+ # Weekly Strike Activity Method
38
+ #
39
+ # Calls #build_activity_message(activity)
40
+ # where activity would be the weekly strike.
41
+ #
42
+ def weekly(response)
43
+ # Set up our client
44
+ destiny_client = DestinyAPI::Base.new(api_key)
45
+ # Build the activity message with weekly info
46
+ build_activity_message(destiny_client.weekly_strike, response)
47
+ end
48
+
49
+ # Xur Items Method
50
+ #
51
+ # Calls #build_xur_message()
52
+ # Returns Xur inventory when availible.
53
+ #
54
+ def xur(response)
55
+ build_xur_message(response)
56
+ end
57
+
58
+ # Begin private methods
59
+ #
60
+ private
61
+
62
+ # Set our api_key for calling in route methods.
63
+ #
64
+ def api_key
65
+ config.api_key
66
+ end
67
+
68
+ # Generalized Response Method
69
+ #
70
+ # Used by activity methods to bring concise activity info
71
+ # into the chat.
72
+ #
28
73
  def build_activity_message(activity, response)
29
- activity = activity
30
- response.reply("#{activity["activityName"]}\n #{activityDescription["activityDescription"]}\n #{skulls["skulls"]}")
74
+ # Set activity
75
+ activity_hash = activity
76
+ # Send response
77
+ response.reply("#{activity_hash[:activityName]}\n#{activity_hash[:activityDescription]}\nSkulls: #{activity_hash[:skulls].join(', ')}")
31
78
  end
32
-
33
- end
34
79
 
80
+ # Xur Response Method
81
+ #
82
+ # Builds response to bring Xur items into chat.
83
+ #
84
+ def build_xur_message(response)
85
+ # Set up our client
86
+ destiny_client = DestinyAPI::Base.new(api_key)
87
+ # Set xur to our clients xur method
88
+ xur = destiny_client.xur
89
+ # Check vendorDetails to see if anything is availible.
90
+ if xur[:vendorDetails].nil?
91
+ # If nothing, send to chat that he isn't there.
92
+ response.reply "Xur isn't in the tower right now."
93
+ else
94
+ # If something, send to chat what he is selling.
95
+ response.reply "Xur is selling: "
96
+ end
97
+ end
98
+ end
99
+
100
+ # Register the handler
35
101
  Lita.register_handler(Destiny)
36
102
  end
37
103
  end
data/lib/lita-destiny.rb CHANGED
@@ -1,13 +1,16 @@
1
1
  require "lita"
2
2
 
3
+ # Bring in locales from '/locales/*.yml'
3
4
  Lita.load_locales Dir[File.expand_path(
4
5
  File.join("..", "..", "locales", "*.yml"), __FILE__
5
6
  )]
6
7
 
7
- require "destiny/destiny_api"
8
+ # Require core files
9
+ require "destiny/base_api"
8
10
  require "lita/handlers/destiny"
9
11
 
12
+ # Require response templates
10
13
  Lita::Handlers::Destiny.template_root File.expand_path(
11
14
  File.join("..", "..", "templates"),
12
15
  __FILE__
13
- )
16
+ )
data/lita-destiny.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-destiny"
3
- spec.version = "0.1.2"
3
+ spec.version = "0.1.3"
4
4
  spec.authors = ["PDaily"]
5
5
  spec.email = ["pat.irwin4@gmail.com"]
6
6
  spec.description = "Small lita.io handler for interacting with the Destiny API"
@@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rspec", "~> 3.0", ">= 3.0.0"
25
25
  spec.add_development_dependency "simplecov", "~> 0.10", ">= 0.10.0"
26
26
  spec.add_development_dependency "coveralls", "~> 0.8", ">= 0.8.1"
27
+ spec.add_development_dependency "codeclimate-test-reporter"
27
28
  end
@@ -1,14 +1,13 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lita::Handlers::Destiny, lita_handler: true do
4
- let(:api_token) { 'abcd-1234567890-hWYd21AmMH2UHAkx29vb5c1Y' }
5
- let(:config) { Lita::Adapters::Destiny.configuration_builder.build }
4
+ let(:api_key) { 'd319ebf361e9f4f28e65fa05ce1cf8d6' }
5
+ let(:config) { Lita::Handlers::Destiny.configuration_builder.build }
6
6
 
7
7
  before do
8
- config.api_token = api_token
8
+ config.api_key = api_key
9
9
  end
10
10
 
11
11
  it { is_expected.to route_command("!nightfall").to(:nightfall)}
12
12
 
13
-
14
13
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require "simplecov"
2
2
  require "coveralls"
3
+ require "codeclimate-test-reporter"
4
+
5
+ CodeClimate::TestReporter.start
6
+
3
7
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
8
  SimpleCov::Formatter::HTMLFormatter,
5
9
  Coveralls::SimpleCov::Formatter
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-destiny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - PDaily
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: 0.8.1
181
+ - !ruby/object:Gem::Dependency
182
+ name: codeclimate-test-reporter
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
181
195
  description: Small lita.io handler for interacting with the Destiny API
182
196
  email:
183
197
  - pat.irwin4@gmail.com
@@ -191,7 +205,7 @@ files:
191
205
  - LICENSE
192
206
  - README.md
193
207
  - Rakefile
194
- - lib/destiny/destiny_api.rb
208
+ - lib/destiny/base_api.rb
195
209
  - lib/lita-destiny.rb
196
210
  - lib/lita/handlers/destiny.rb
197
211
  - lita-destiny.gemspec