lita-destiny 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4f8fff55885215ad537fdf8426014f984537740
4
- data.tar.gz: d46388aec3dcf560cb2d25f827bf440208e774fd
3
+ metadata.gz: 273db0f6ec1165b2bfb680c9adb3dbb17784d983
4
+ data.tar.gz: 8a77938f5edd415ec959fe837f8f1d853c2b83e3
5
5
  SHA512:
6
- metadata.gz: 216d833748bd8518b54447d08a1617f27414d9b8a7267cf0bf7889f107308dd7eb49740233c36a67f9e355dac9349417ffd5b208bd81bef766b28f086083d24d
7
- data.tar.gz: 7fdcf111a0a6b24ba9d8702cc5ac24d053309f2a20f4e2d9ae92c763305c4513a54154c7cd954c3994531aa55709d8863a801da89b366d963374f793feb2579e
6
+ metadata.gz: 93111e093fb4d5001ad794df9017067859138d5611984921fcf2fbc8fa0be319d80eb2334b639afc6cf1d9692f7d815df084c461f4ccb0d8ec42b3c70b835ff8
7
+ data.tar.gz: 88f9029bc6439c23e1fe82f871acd8e9597c5d66eac40d3d8034293263a99642fc5762703bd9cabd2601d8e85636e57c2a9e42a9d26b95f16cdbebf36f871458
@@ -1,83 +1,85 @@
1
1
  require 'httparty'
2
2
 
3
- module DestinyApi
4
- include HTTParty
5
- format :json
6
- base_uri 'www.bungie.net/platform/destiny/'
3
+ module DestinyAPI
4
+ class Base
5
+ include HTTParty
6
+ format :json
7
+ base_uri 'www.bungie.net/platform/destiny/'
7
8
 
8
9
 
9
- # Init the Destiny API with Bungie API stored in ENV variable
10
- # destiny = Destiny.new(api_token)
11
- def initialize(api_token)
12
- @headers = { 'X-API-Key' => api_token, 'Content-Type' => 'application/json' }
13
- end
14
-
15
- # Pull the days advisor report from http://www.bungie.net/platform/destiny/advisors/
16
- # destiny.advisors
17
- def advisors
18
- raw_data = self.class.get('/advisors', headers: @headers)
19
- parsed = raw_data.parsed_response['Response']['data']
20
- end
10
+ # Init the Destiny API with Bungie API stored in ENV variable
11
+ # destiny = Destiny.new(api_token)
12
+ def initialize(api_token)
13
+ @headers = { 'X-API-Key' => api_token, 'Content-Type' => 'application/json' }
14
+ end
21
15
 
22
- def activity(activity_hash, raw=false)
23
- raw_data = self.class.get("/manifest/activity/#{activity_hash}").parsed_response['Response']['data']['activity']
24
- skulls = []
25
- raw_data['skulls'].each do |skull|
26
- skulls << skull['displayName']
16
+ # Pull the days advisor report from http://www.bungie.net/platform/destiny/advisors/
17
+ # destiny.advisors
18
+ def advisors
19
+ raw_data = self.class.get('/advisors', headers: @headers)
20
+ parsed = raw_data.parsed_response['Response']['data']
27
21
  end
28
- unless raw == true
29
- parsed_data = { activityName: raw_data['activityName'], activityDescription: raw_data['activityDescription'], skulls: skulls }
30
- else
31
- raw_data
22
+
23
+ def activity(activity_hash, raw=false)
24
+ raw_data = self.class.get("/manifest/activity/#{activity_hash}").parsed_response['Response']['data']['activity']
25
+ skulls = []
26
+ raw_data['skulls'].each do |skull|
27
+ skulls << skull['displayName']
28
+ end
29
+ unless raw == true
30
+ parsed_data = { activityName: raw_data['activityName'], activityDescription: raw_data['activityDescription'], skulls: skulls }
31
+ else
32
+ raw_data
33
+ end
32
34
  end
33
- end
34
35
 
35
- # Pull the weekly nightfall info from http://www.bungie.net/platform/destiny/manifest/activity/#{activity_hash}
36
- # Optional boolean argument, defaults to false from activity method to only return basic information for Lita bot.
37
- #
38
- # destiny.nightfall
39
- #
40
- def nightfall(options={})
41
- nightfall_activity_hash = self.advisors['nightfallActivityHash']
42
- activity(nightfall_activity_hash, boolean)
43
- end
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.
38
+ #
39
+ # destiny.nightfall
40
+ #
41
+ def nightfall(options={})
42
+ nightfall_activity_hash = self.advisors['nightfallActivityHash']
43
+ activity(nightfall_activity_hash, boolean)
44
+ end
44
45
 
45
- # Pull the weekly nightfall info from http://www.bungie.net/platform/destiny/manifest/activity/#{activity_hash}
46
- # Returns an array of three items, only need one for the skulls and location.
47
- #
48
- # Optional boolean argument, defaults to false from activity method to return basic information for Lita bot.
49
- #
50
- # destiny.weekly_strike(false)
51
- #
52
- def weekly_strike(options={})
53
- heroic_strike_hashes = self.advisors['heroicStrikeHashes']
54
- activity(heroic_strike_hashes[0], boolean)
55
- end
46
+ # Pull the weekly nightfall info from http://www.bungie.net/platform/destiny/manifest/activity/#{activity_hash}
47
+ # Returns an array of three items, only need one for the skulls and location.
48
+ #
49
+ # Optional boolean argument, defaults to false from activity method to return basic information for Lita bot.
50
+ #
51
+ # destiny.weekly_strike(false)
52
+ #
53
+ def weekly_strike(options={})
54
+ heroic_strike_hashes = self.advisors['heroicStrikeHashes']
55
+ activity(heroic_strike_hashes[0], boolean)
56
+ end
56
57
 
57
- # Pull the weekly nightfall info from http://www.bungie.net/platform/destiny/manifest/activity/#{activity_hash}
58
- #
59
- #
60
- # No known endpoints.
61
- def arena(options={})
62
- end
58
+ # Pull the weekly nightfall info from http://www.bungie.net/platform/destiny/manifest/activity/#{activity_hash}
59
+ #
60
+ #
61
+ # No known endpoints.
62
+ def arena(options={})
63
+ end
63
64
 
64
- # WIP: Pull xur inventory
65
- # http://www.bungie.net/platform/destiny/advisors/xur/?definitions=true
66
- def xur
67
- raw_data = self.class.get('/advisors/xur/?definitions=true').parsed_response['Response']['definitions']
68
- end
65
+ # WIP: Pull xur inventory
66
+ # http://www.bungie.net/platform/destiny/advisors/xur/?definitions=true
67
+ def xur
68
+ raw_data = self.class.get('/advisors/xur/?definitions=true').parsed_response['Response']['definitions']
69
+ end
69
70
 
70
- # Pull the days bounties
71
- def bounties
72
- end
71
+ # Pull the days bounties
72
+ def bounties
73
+ end
73
74
 
74
- def place(place_hash)
75
- raw data = self.class.get('/manifest/place/#{place_hash}').parsed_response['Response']['data']['place']
76
- response = { place_name: raw_data['placeName'], place_desc: raw_data['placeDescription'] }
77
- end
75
+ def place(place_hash)
76
+ raw data = self.class.get('/manifest/place/#{place_hash}').parsed_response['Response']['data']['place']
77
+ response = { place_name: raw_data['placeName'], place_desc: raw_data['placeDescription'] }
78
+ end
78
79
 
79
- def destination(destination_hash)
80
- raw_data = self.class.get('/manifest/destination/#{destination_hash}').parsed_response['Response']['data']
81
- response = { dest_name: raw_data['destinationName'], dest_desc: raw_data['destinationDescription'] }
80
+ def destination(destination_hash)
81
+ raw_data = self.class.get('/manifest/destination/#{destination_hash}').parsed_response['Response']['data']
82
+ response = { dest_name: raw_data['destinationName'], dest_desc: raw_data['destinationDescription'] }
83
+ end
82
84
  end
83
85
  end
@@ -1,20 +1,33 @@
1
1
  module Lita
2
2
  module Handlers
3
3
  class Destiny < Handler
4
- include DestinyApi
5
- config :api_key
4
+ namespace "destiny"
5
+ # Bring in DestinyAPI module
6
+ include DestinyAPI
6
7
 
7
- DESTINY = DestinyApi.new(config.api_key)
8
+ # Required configuration attribute
9
+ config :api_key, type: String, required: true do
10
+ validate do |value|
11
+ "must be 32 characters" unless value.respond_to?(:size) && value.size == 32
12
+ end
13
+ end
8
14
 
9
- route(/!+?\b(nightfall)/i, :build_activity_message(DESTINY.nightfall), help: { "!nightfall" => "Get this weeks nightfall description and skulls" })
15
+
16
+ # Set up our client
17
+ destiny_client = DestinyAPI::Base.new(config.api_key).call
18
+
19
+
20
+ route(/^!\w(.*)/i, :nightfall , help: { "!nightfall" => "Get this weeks nightfall description and skulls" })
10
21
 
11
22
 
23
+ def nightfall(response)
24
+ build_activity_message(destiny_client.nightfall, response)
25
+ end
12
26
 
13
27
  # activity = { activityName: raw_data['activityName'], activityDescription: raw_data['activityDescription'], skulls: skulls }
14
- def build_activity_message(activity)
28
+ def build_activity_message(activity, response)
15
29
  activity = activity
16
- #response.reply("#{activity["activityName"]}\n #{activityDescription["activityDescription"]}\n #{skulls["skulls"]}")
17
- response.reply("Hi!")
30
+ response.reply("#{activity["activityName"]}\n #{activityDescription["activityDescription"]}\n #{skulls["skulls"]}")
18
31
  end
19
32
 
20
33
  end
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.1"
3
+ spec.version = "0.1.2"
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"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-destiny
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - PDaily
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita