omniauth-expressov3 1.0.4 → 1.0.5

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,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NmQ0OGM2MmVlMTEzZmQ0ZDlkMjdiY2FhYjFlZDQ1ZGE3ZTQ1NDI2Nw==
4
+ YjA2YjZhZThlN2QyMzUwYWFjMGVkNTczNDliMzNkNjc5YzlkMDY4Ng==
5
5
  data.tar.gz: !binary |-
6
- OTg3MDI1MmMwODQ0ZmViMTk2Y2JjNTg1OWI1MmIyYmZmMTQ3Nzg5Mw==
6
+ MjM3OWIwNzk2MDczODE3YWM0OTg0ZDhhOWI5OTlmYWE4MmVkODc2NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjBiZDA3NmVjM2Y1ODllNTM0ZGFmNWZkYTUwYWE4N2U4YmJhOGI3MmU5MDI5
10
- Y2NlYzc1ODNlNGI3NTY1MWRiZGI1MDZmY2YyMWY2MmJkMmM1YjYxOWRiNDA1
11
- NWZkYjU0MzNjMTc5YTNlMzYyNDMwM2M4ZWY2Zjk1NTFjZDI4MTU=
9
+ MGFlZmJmZTk1OTBjMjkwMTZjMmEzNmZkZWU5OWQ2ZDE1Nzc3MzZkN2YxYjll
10
+ Yjk1MGNkMmUzZjE5NWU1MmE0YmFjMzYyYjFlZmMxODg1Y2IyNTQyOWU5ZTBl
11
+ YmFiOWI0OGUzODJiNGJkYzRlZGUxOTM0ODJhNDhjNWU5YTY0Mzc=
12
12
  data.tar.gz: !binary |-
13
- YmUwZTA1NDNmNjYyOTlmM2JiYTk1YmM4YjhkYTVlZDk5YWI2YjIxMmYwYmYw
14
- MjZmZjRlNzAzNjQ5ZTg4MTA5MTA1ZGUyYTFjM2E5YTE3NmEwNjc3MGJjZmEw
15
- YTQ1ZDMzNjAyYWEzNThiMThmN2I3ZjUwMjRkNDVkMzQxNzc5OTU=
13
+ OWE4NjIyODUyOTFkNWJjNmRjOTg2NmM0YWE1MGI0NTU0Yzk4MGJmODU5NGI4
14
+ MGU2NDkwY2JjYWM5YWI5MzRlMjBhY2U2NTExNThhNWJhMzJkMzRiMWZiMjA4
15
+ NDI1ZGM3NDJiOWZiYzg2NGE1OTRjZTNiN2M0YjA1YWM2N2FmYzY=
data/Gemfile CHANGED
@@ -8,6 +8,11 @@ group :development, :test do
8
8
  gem 'guard-bundler'
9
9
  gem 'growl'
10
10
  gem 'rb-fsevent'
11
+ gem 'highline'
12
+ gem "codeclimate-test-reporter", group: :test, require: nil
13
+ gem 'awesome_print'
14
+ gem 'debugger'
11
15
  end
12
16
 
13
- gem "codeclimate-test-reporter", group: :test, require: nil
17
+
18
+ gem 'recursive-open-struct'
data/Gemfile.lock CHANGED
@@ -1,17 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- omniauth-expressov3 (1.0.3)
4
+ omniauth-expressov3 (1.0.5)
5
5
  omniauth (~> 1.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
+ awesome_print (1.6.1)
10
11
  celluloid (0.16.0)
11
12
  timers (~> 4.0.0)
12
13
  codeclimate-test-reporter (0.4.6)
13
14
  simplecov (>= 0.7.1, < 1.0.0)
14
15
  coderay (1.1.0)
16
+ columnize (0.9.0)
17
+ debugger (1.6.8)
18
+ columnize (>= 0.3.1)
19
+ debugger-linecache (~> 1.2.0)
20
+ debugger-ruby_core_source (~> 1.3.5)
21
+ debugger-linecache (1.2.0)
22
+ debugger-ruby_core_source (1.3.7)
15
23
  diff-lcs (1.2.5)
16
24
  docile (1.1.5)
17
25
  ffi (1.9.6)
@@ -36,6 +44,7 @@ GEM
36
44
  guard-compat (~> 1.1)
37
45
  rspec (>= 2.99.0, < 4.0)
38
46
  hashie (3.4.0)
47
+ highline (1.6.21)
39
48
  hitimes (1.2.2)
40
49
  listen (2.8.5)
41
50
  celluloid (>= 0.15.2)
@@ -63,6 +72,7 @@ GEM
63
72
  rb-fsevent (0.9.4)
64
73
  rb-inotify (0.9.5)
65
74
  ffi (>= 0.5.0)
75
+ recursive-open-struct (0.5.0)
66
76
  rspec (2.99.0)
67
77
  rspec-core (~> 2.99.0)
68
78
  rspec-expectations (~> 2.99.0)
@@ -86,15 +96,19 @@ PLATFORMS
86
96
  ruby
87
97
 
88
98
  DEPENDENCIES
99
+ awesome_print
89
100
  codeclimate-test-reporter
101
+ debugger
90
102
  growl
91
103
  guard
92
104
  guard-bundler
93
105
  guard-rspec
106
+ highline
94
107
  maruku (~> 0.6)
95
108
  omniauth-expressov3!
96
109
  rack-test (~> 0.5)
97
110
  rake (~> 0.8)
98
111
  rb-fsevent
112
+ recursive-open-struct
99
113
  rspec (~> 2.7)
100
114
  simplecov (~> 0.4)
@@ -79,11 +79,10 @@ module OmniAuth
79
79
  user = {}
80
80
  mapper.each do |key, value|
81
81
  values_keys = value.split('::')
82
- value_key = values_keys[0]
83
- sub_value_key = values_keys[1]
84
-
85
- if object && object.has_key?(value_key) && object[value_key] && object[value_key].has_key?(sub_value_key)
86
- user[key] = object[value_key][sub_value_key]
82
+ value_key = values_keys[0].to_sym
83
+ sub_value_key = values_keys[1].to_sym
84
+ if object && object.respond_to?(value_key) && object.send(value_key) && object.send(value_key).respond_to?(sub_value_key)
85
+ user[key] = object.send(value_key).send(sub_value_key)
87
86
  else
88
87
  user[key] = nil
89
88
  end
@@ -1,3 +1,4 @@
1
+ require 'recursive-open-struct'
1
2
  module OmniAuth
2
3
  module ExpressoV3
3
4
  class AuthClient
@@ -30,23 +31,22 @@ module OmniAuth
30
31
  # check if user is authenticated, raises an authentication if not
31
32
  validate_login(@json_tine.result)
32
33
  #return user data
33
- @json_tine.result
34
+ build_struct @json_tine.result
34
35
  end
35
36
 
36
37
  def send method, args=nil
37
38
  @json_tine.send method, args
38
- @json_tine.result
39
+ build_struct @json_tine.result
39
40
  end
40
41
 
41
42
  def get_user_data
42
43
  #request to get user data
43
44
  @json_tine.send 'Tinebase.getAllRegistryData'
44
- #hash with user data
45
- { 'keys' => @json_tine.result['keys'],
46
- 'currentAccount' => @json_tine.result['Tinebase']['currentAccount'],
47
- 'userContact' => @json_tine.result['Tinebase']['userContact'],
48
- 'expressoAccount' => @json_tine.result['Expressomail']['accounts']['results'][0]
49
- }
45
+ # hash with user data
46
+ build_struct :keys => @json_tine.result['keys'],
47
+ :currentAccount => @json_tine.result['Tinebase']['currentAccount'],
48
+ :userContact => @json_tine.result['Tinebase']['userContact'],
49
+ :expressoAccount => @json_tine.result['Expressomail']['accounts']['results'][0]
50
50
  end
51
51
 
52
52
  def last_raw_data
@@ -57,7 +57,9 @@ module OmniAuth
57
57
  @json_tine.close if @json_tine
58
58
  end
59
59
  protected
60
-
60
+ def build_struct hash
61
+ RecursiveOpenStruct.new hash, :recurse_over_arrays => true
62
+ end
61
63
  def validate_arguments(username, password)
62
64
  if username.nil? or password.nil?
63
65
  raise MissingArgumentsError.new('missing credentials arguments')
@@ -1,6 +1,8 @@
1
1
  require 'net/http'
2
2
  require 'rubygems'
3
3
  require 'json'
4
+ require 'ostruct'
5
+ require 'forwardable'
4
6
  module OmniAuth
5
7
  module ExpressoV3
6
8
  #classe para fazer a conexão com o expresso3/tine20
@@ -37,7 +39,6 @@ module OmniAuth
37
39
  end
38
40
 
39
41
  def send(tine_method, args=nil)
40
- puts "STARTING METHOD: #{tine_method} - WITH PARAMS: #{args.inspect}" if @debug
41
42
  response = execute_http_call(tine_method, args)
42
43
  hash_response = parse_response(response)
43
44
  @json_return = hash_response[:json_object]
@@ -59,6 +60,7 @@ module OmniAuth
59
60
  @last_body
60
61
  end
61
62
 
63
+
62
64
  def result
63
65
  if @json_return['result']
64
66
  keys.merge(@json_return['result'])
@@ -83,6 +85,7 @@ module OmniAuth
83
85
  end
84
86
 
85
87
  private
88
+
86
89
  def execute_http_call(tine_method, args=nil)
87
90
  @req = Net::HTTP::Post.new(@uri.request_uri, initheader = {'Content-Type'=>'application/json'})
88
91
  json_body = {:jsonrpc => '2.0', :method => tine_method, :id => next_cont}
@@ -90,21 +93,19 @@ private
90
93
 
91
94
  #puts "REQUEST BODY: #{json_body.to_json}" if @debug
92
95
 
93
- @req.body = uri_escape_sanely( json_body.to_json )
96
+ @req.body = json_body.to_json #uri_escape_sanely( json_body.to_json )
94
97
  add_request_fields #headers e cookies
95
98
  unless @http
96
99
  @http = Net::HTTP.new(@uri.host, @uri.port)
97
100
  @http.use_ssl = true
98
101
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
99
102
  end
103
+ @http.set_debug_output($stdout) if @debug
100
104
  return @http.start {|http| @http.request(@req) }
101
105
  end
102
106
 
103
107
  def parse_response response
104
- # puts "BODY: #{response.body}" if @debug
105
108
  json_obj = JSON.parse(response.body)
106
- # puts json_obj.inspect if @debug
107
-
108
109
 
109
110
  if json_obj['result'] and json_obj['result'].is_a? Hash
110
111
  json_key = json_obj['result']['jsonKey'] if json_obj['result']['jsonKey']
@@ -130,6 +131,7 @@ private
130
131
 
131
132
  def output_debug_response_and_vars(response)
132
133
  if @debug
134
+ puts response.body
133
135
  #puts "Response #{response.code} #{response.message}: #{response.body}"
134
136
  puts "TINE_KEY: "+@tine_key if @tine_key
135
137
  puts "JSON_KEY: "+@json_key if @json_key
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module ExpressoV3
3
- VERSION = '1.0.4'
3
+ VERSION = '1.0.5'
4
4
  end
5
5
  end
@@ -2,6 +2,12 @@ require 'spec_helper'
2
2
  require 'json'
3
3
  describe "OmniAuth::Strategies::ExpressoV3" do
4
4
 
5
+ before :all do
6
+ display_label 'TESTING EXPRESSO V3 AUTHCLIENT'
7
+ ENV['EXPRESSO_USERNAME'] ||= ask('Expresso Username: ')
8
+ ENV['EXPRESSO_PASSWORD'] ||= ask("Expresso password for #{ENV['EXPRESSO_USERNAME']}: ") { |q| q.echo = false }
9
+ end
10
+
5
11
  class ExpressoV3Provider < OmniAuth::Strategies::ExpressoV3; end
6
12
 
7
13
  let(:app) do
@@ -109,7 +115,7 @@ describe "OmniAuth::Strategies::ExpressoV3" do
109
115
 
110
116
  it 'should redirect to error page' do
111
117
  post('/auth/expressov3/callback', {:username => "ping", :password => "password"})
112
-
118
+ #require 'debugger'; debugger
113
119
  expect(last_response).to be_redirect
114
120
  expect(last_response.headers['Location']).to match(%r{expressov3_error})
115
121
  end
@@ -1,16 +1,24 @@
1
1
  require 'spec_helper'
2
2
  describe "OmniAuth::ExpressoV3::AuthClient" do
3
3
 
4
+ before :all do
5
+ display_label 'TESTING EXPRESSO V3 AUTHCLIENT'
6
+ ENV['EXPRESSO_USERNAME'] ||= ask('Expresso Username: ')
7
+ ENV['EXPRESSO_PASSWORD'] ||= ask("Expresso password for #{ENV['EXPRESSO_USERNAME']}: ") { |q| q.echo = false }
8
+ #unmute! - habilita os outputs de debug do test
9
+ end
10
+
4
11
  describe 'authenticate' do
5
12
  it 'should authenticate' do
6
- auth = OmniAuth::ExpressoV3::AuthClient.new
13
+ auth = OmniAuth::ExpressoV3::AuthClient.new :debug => false
7
14
  auth_data = auth.authenticate(ENV['EXPRESSO_USERNAME'], ENV['EXPRESSO_PASSWORD'])
8
15
  expect(auth_data).not_to be(nil)
9
- expect(auth_data['keys']).not_to be(nil)
16
+
17
+ expect(auth_data.keys).not_to be(nil)
10
18
  data = auth.get_user_data
11
19
 
12
- expect(data['currentAccount']).not_to be(nil)
13
- expect(data['userContact']).not_to be(nil)
20
+ expect(data.currentAccount).not_to be(nil)
21
+ expect(data.userContact).not_to be(nil)
14
22
  auth.close
15
23
  end
16
24
  end
@@ -33,58 +41,73 @@ describe "OmniAuth::ExpressoV3::AuthClient" do
33
41
  args = {
34
42
  filter:
35
43
  [
36
- {field: "account_id", operator: "equals", value: @user_data["expressoAccount"]["id"]},
44
+ {field: "account_id", operator: "equals", value: @user_data.expressoAccount.id},
37
45
  {field: "globalname", operator: "equals", value: ""}
38
46
 
39
47
  ]
40
48
  }
41
49
  result = @auth.send("Expressomail.searchFolders", args)
42
- puts "----------------------------------------------------------"
43
- puts "PRINTING FOLDERS"
44
- puts "----------------------------------------------------------"
45
- result['results'].each do |folder|
46
- puts "FOLDER: #{folder['id']} - #{folder['globalname']} (#{folder['cache_totalcount']}) emails (#{folder['cache_unreadcount']}) unread"
47
- puts "FOLDER DATA: #{folder.inspect}"
48
- puts "----------------------------------------------------------"
50
+ display_label "PRINTING FOLDERS"
51
+ result.results.each do |folder|
52
+ p "FOLDER: #{folder.id} - #{folder.globalname} (#{folder.cache_totalcount}) emails (#{folder.cache_unreadcount}) unread"
53
+ p "FOLDER DATA: "
54
+ puts_object folder
55
+ display_line
49
56
  end
50
57
  end
51
- it 'search Messages' do
52
- args = {
53
- filter:
54
- [
55
- {
56
- condition: "OR",
57
- filters: [
58
- {condition: "AND", filters: [{field: "query", operator: "contains", value: "", id: "ext-record-351"},
59
- { field: "path", operator: "in",
60
- value: ["/4e3f366969900893e80664b9c745a254f451aacb/NGUzZjM2Njk2OTkwMDg5M2U4MDY2NGI5Yzc0NWEyNTRmNDUxYWFjYjtJTkJPWA2"],
61
- id: "ext-record-368"}],
62
- id: "ext-comp-1101", label: "Messages"}]}],
63
- paging:
64
- {
65
- sort: "received", dir: "DESC", start: 0, limit: 5
66
- }
67
- }
68
- result = @auth.send("Expressomail.searchMessages", args)
69
- puts "----------------------------------------------------------"
70
- puts "LSITING LAST 5 MESSAGES"
71
- puts "----------------------------------------------------------"
72
- (0..4).each do |i|
73
- puts "SUBJECT: #{result['results'][i]['subject']}"
74
- puts "EMAIL DATA: #{result['results'][i].inspect}"
75
- puts "----------------------------------------------------------"
58
+
59
+ context "messages" do
60
+ let(:inbox_folder) do
61
+ args = {
62
+ filter:
63
+ [
64
+ {field: "account_id", operator: "equals", value: @user_data.expressoAccount.id},
65
+ {field: "globalname", operator: "equals", value: ""}
66
+
67
+ ]
68
+ }
69
+ result = @auth.send("Expressomail.searchFolders", args)
70
+ folder = result.results.first
71
+ end
72
+ it 'search Messages' do
73
+ inbox_id = inbox_folder.id
74
+ account_id = @user_data.expressoAccount.id
75
+ args = {
76
+ filter:
77
+ [
78
+ {
79
+ condition: "OR",
80
+ filters: [
81
+ {condition: "AND", filters: [{field: "query", operator: "contains", value: "", id: "ext-record-351"},
82
+ { field: "path", operator: "in",
83
+ value: ["/#{account_id}/#{inbox_id}"],
84
+ id: "ext-record-368"}],
85
+ id: "ext-comp-1101", label: "Messages"}]}],
86
+ paging:
87
+ {
88
+ sort: "received", dir: "DESC", start: 0, limit: 5
89
+ }
90
+ }
91
+ response = @auth.send("Expressomail.searchMessages", args)
92
+
93
+ display_label "LISTING LAST 5 MESSAGES"
94
+
95
+ response.results.each do |msg|
96
+ p "SUBJECT: #{msg.subject}"
97
+ p "EMAIL DATA: "
98
+ puts_object msg
99
+ display_line
100
+ end
101
+ end
102
+ it 'query for Expressomail.updateMessageCache' do
103
+ args = {
104
+ folderId: inbox_folder.id,
105
+ time: 10
106
+ }
107
+ result = @auth.send("Expressomail.updateMessageCache", args)
108
+ display_label "UPDATING MESSAGES CACHE"
109
+ puts_object result
76
110
  end
77
- end
78
- it 'query for Expressomail.updateMessageCache' do
79
- args = {
80
- folderId: 'NGUzZjM2Njk2OTkwMDg5M2U4MDY2NGI5Yzc0NWEyNTRmNDUxYWFjYjtJTkJPWA2',
81
- time: 10
82
- }
83
- result = @auth.send("Expressomail.updateMessageCache", args)
84
- puts "----------------------------------------------------------"
85
- puts "UPDATING MESSAGES CACHE"
86
- puts "----------------------------------------------------------"
87
- puts result
88
111
  end
89
112
  end
90
113
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "codeclimate-test-reporter"
2
+ require 'highline/import'
3
+ require 'awesome_print'
2
4
  CodeClimate::TestReporter.start
3
5
 
4
6
  $:.unshift File.expand_path('..', __FILE__)
@@ -16,3 +18,39 @@ RSpec.configure do |config|
16
18
 
17
19
  OmniAuth.config.logger = Logger.new(File.expand_path('../omniauth.log', __FILE__))
18
20
  end
21
+
22
+ def muted?
23
+ @@mute
24
+ end
25
+
26
+ def mute!
27
+ @@mute = true
28
+ end
29
+
30
+ def unmute!
31
+ @@mute = false
32
+ end
33
+
34
+ @@mute = true
35
+
36
+ def display_label label
37
+ return if muted?
38
+ puts ''
39
+ display_line
40
+ if label
41
+ puts label
42
+ display_line
43
+ end
44
+ end
45
+
46
+ def display_line
47
+ puts '-' * HighLine::SystemExtensions.terminal_size[0] unless muted?
48
+ end
49
+
50
+ def p msg
51
+ puts msg unless muted?
52
+ end
53
+
54
+ def puts_object object
55
+ ap object unless muted?
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-expressov3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abner Oliveira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth