jive-tile 0.0.3 → 0.0.5

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: 119de7f2faf6680a5ffbf013f512f92f11d0a77d
4
- data.tar.gz: 7b6bcdf67bd57f7d8a28d272e7c404ba02d6bd51
3
+ metadata.gz: c76114bed4cd8a488494306e87d3cddd3a7fa13e
4
+ data.tar.gz: 94722ef33dd1b1b85cd2ce67adaaddea2e651d5f
5
5
  SHA512:
6
- metadata.gz: 0f2ad2858932a9f7dbe54e9c13d820326b7bbe15fcc3240774e3949dab6260fe41f7e12bbacdbf73ab4c8cae14081dc523a5203453026b9024cd34ae30cf6860
7
- data.tar.gz: 3dc656eca9bd1434932978e02088ad8bddfdee3a28c73c329bb30918e9e85be92c0f5cc690ea884dd6e17b23cb1e6d7f7eee7dc0a7ba55c3138ef7166da966c2
6
+ metadata.gz: 3f78a0628b42e53c0d36ccedb455f6af475d72c390a8ff183c265d0bfe1f3ecb20ec2253fe6f01da6bcb6031708ba0d4da1ed0bdcac4ad2c979fa007553eade4
7
+ data.tar.gz: 20a7f8f2ddd5475e6ddc005345653b7b716d7fa4ecf84e7e98aa2ddac94aaf792a5d9958de99b278461a825e0d7acf27256acee3c6dd7660615d5aa37f876da8
@@ -3,6 +3,7 @@ class AddJiveTiles010Migration < ActiveRecord::Migration
3
3
  create_table :jive_tiles do |t|
4
4
  t.integer :jive_add_on_id
5
5
 
6
+ t.integer :tile_id
6
7
  t.string :code
7
8
  t.text :config
8
9
  t.string :guid
@@ -25,7 +26,8 @@ class AddJiveTiles010Migration < ActiveRecord::Migration
25
26
  create_table :jive_tiles_oauth_tokens do |t|
26
27
  t.string :scope
27
28
  t.string :token_type
28
- t.string :expires_in
29
+ t.integer :expires_in
30
+ t.timestamp :expires_at
29
31
  t.string :refresh_token
30
32
  t.string :access_token
31
33
 
@@ -1,9 +1,51 @@
1
1
  module Jive
2
2
  module Tile
3
3
  class Model < ActiveRecord::Base
4
- belongs_to :add_on, :class_name => "Jive::AddOn::Model", :foreign_key => :jive_add_on_id
5
4
  self.table_name = :jive_tiles
5
+ belongs_to :add_on, :class_name => "Jive::AddOn::Model", :foreign_key => :jive_add_on_id
6
+ belongs_to :oauth_token, :class_name => "Jive::Tile::OAuthToken", :foreign_key => :jive_tiles_oauth_token_id
6
7
  serialize :config, Hash
8
+
9
+ after_create :fetch_oauth_token
10
+
11
+ private
12
+ def fetch_oauth_token
13
+ require "open-uri"
14
+ require "net/http"
15
+ require "openssl"
16
+
17
+ uri = URI.parse("#{self.add_on.jive_url}/oauth2/token")
18
+ http = Net::HTTP.new(uri.host, uri.port)
19
+ http.use_ssl = true
20
+
21
+ request = Net::HTTP::Post.new(uri.request_uri)
22
+
23
+ request["Content-Type"] = "application/x-www-form-urlencoded"
24
+ request.basic_auth(self.add_on.client_id, self.add_on.client_secret)
25
+ request.set_form_data({
26
+ "code" => self.code,
27
+ "grant_type" => "authorization_code",
28
+ "client_id" => self.add_on.client_id,
29
+ })
30
+
31
+ response = http.request(request)
32
+
33
+ # Got access token from Jive
34
+ if (response.code.to_i === 200)
35
+ json_body = JSON.parse(response.body)
36
+
37
+ # Create
38
+ Jive::Tile::OauthToken.create(
39
+ :tile => self,
40
+ :scope => json_body["scope"],
41
+ :token_type => json_body["token_type"],
42
+ :expires_in => json_body["expires_in"],
43
+ :expires_at => json_body["expires_in"].to_i.seconds.from_now,
44
+ :refresh_token => json_body["refresh_token"],
45
+ :access_token => json_body["access_token"],
46
+ )
47
+ end
48
+ end
7
49
  end
8
50
  end
9
51
  end
@@ -2,7 +2,7 @@ module Jive
2
2
  module Tile
3
3
  class OauthToken < ActiveRecord::Base
4
4
  self.table_name = :jive_tiles_oauth_tokens
5
- has_one :tile, :class_name => "Jive::Tile::Model"
5
+ has_one :tile, :class_name => "Jive::Tile::Model", :foreign_key => :jive_tiles_oauth_token_id
6
6
  end
7
7
  end
8
8
  end
@@ -1,5 +1,5 @@
1
1
  module Jive
2
2
  module Tile
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jive-tile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Butch Marshall
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord