Class: GvoiceRuby::Client
- Inherits:
-
Object
- Object
- GvoiceRuby::Client
- Includes:
- Curl
- Defined in:
- lib/gvoice-ruby/client.rb
Instance Attribute Summary collapse
-
#all_messages ⇒ Object
Returns the value of attribute all_messages.
-
#calls ⇒ Object
Returns the value of attribute calls.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#smss ⇒ Object
Returns the value of attribute smss.
-
#unread_counts ⇒ Object
Returns the value of attribute unread_counts.
-
#user ⇒ Object
Returns the value of attribute user.
-
#voicemails ⇒ Object
Returns the value of attribute voicemails.
Instance Method Summary collapse
- #add_note(options) ⇒ Object
- #any_unread? ⇒ Boolean
- #archive(options) ⇒ Object
- #call(options) ⇒ Object
- #cancel_call(options = {}) ⇒ Object
- #check(parser = GvoiceRuby::InboxParser.new) ⇒ Object
- #delete_note(options) ⇒ Object
-
#initialize(config = GvoiceRuby::Configurator.load_config) ⇒ Client
constructor
A new instance of Client.
- #logged_in? ⇒ Boolean
- #logout ⇒ Object
- #mark_as_read(options) ⇒ Object
- #mark_as_unread(options) ⇒ Object
- #missed(parser = GvoiceRuby::InboxParser.new) ⇒ Object
- #placed(parser = GvoiceRuby::InboxParser.new) ⇒ Object
- #received(parser = GvoiceRuby::InboxParser.new) ⇒ Object
- #send_sms(options, show_details = true) ⇒ Object
- #star(options) ⇒ Object
- #unstar(options) ⇒ Object
Constructor Details
#initialize(config = GvoiceRuby::Configurator.load_config) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gvoice-ruby/client.rb', line 12 def initialize(config = GvoiceRuby::Configurator.load_config) if config[:google_account_email].nil? || config[:google_account_password].nil? raise ArgumentError, "Invalid Google Account username or password provided." else @logger = Logger.new(config.has_key?(:logfile) ? config[:logfile] : File.join(File.dirname(__FILE__), '..', '..', 'log', 'gvoice-ruby.log')) @user = User.new(config[:google_account_email], config[:google_account_password]) @any_unread = [] @unread_counts = {} @all_messages = [] initialize_curb end login(config) set_rnr_se_token # in case _rnr_se scraping fails due to google changing its page content @_rnr_se ||= config[:rnr_se] end |
Instance Attribute Details
#all_messages ⇒ Object
Returns the value of attribute all_messages.
9 10 11 |
# File 'lib/gvoice-ruby/client.rb', line 9 def @all_messages end |
#calls ⇒ Object
Returns the value of attribute calls.
9 10 11 |
# File 'lib/gvoice-ruby/client.rb', line 9 def calls @calls end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/gvoice-ruby/client.rb', line 10 def logger @logger end |
#smss ⇒ Object
Returns the value of attribute smss.
9 10 11 |
# File 'lib/gvoice-ruby/client.rb', line 9 def smss @smss end |
#unread_counts ⇒ Object
Returns the value of attribute unread_counts.
9 10 11 |
# File 'lib/gvoice-ruby/client.rb', line 9 def unread_counts @unread_counts end |
#user ⇒ Object
Returns the value of attribute user.
9 10 11 |
# File 'lib/gvoice-ruby/client.rb', line 9 def user @user end |
#voicemails ⇒ Object
Returns the value of attribute voicemails.
9 10 11 |
# File 'lib/gvoice-ruby/client.rb', line 9 def voicemails @voicemails end |
Instance Method Details
#add_note(options) ⇒ Object
155 156 157 158 159 160 161 162 163 |
# File 'lib/gvoice-ruby/client.rb', line 155 def add_note() fields = [ PostField.content('id', [:id]), PostField.content('note', [:note]), PostField.content('_rnr_se', @_rnr_se) ] .merge!({ :post_url => 'https://www.google.com/voice/inbox/savenote'}) post(, fields) end |
#any_unread? ⇒ Boolean
31 32 33 |
# File 'lib/gvoice-ruby/client.rb', line 31 def any_unread? @any_unread end |
#archive(options) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/gvoice-ruby/client.rb', line 105 def archive() fields = [ PostField.content('messages', [:id]), PostField.content('archive', 1), PostField.content('_rnr_se', @_rnr_se) ] .merge!({ :post_url => 'https://www.google.com/voice/inbox/mark'}) post(, fields) end |
#call(options) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/gvoice-ruby/client.rb', line 81 def call() fields = [ PostField.content('outgoingNumber', [:outgoing_number]), PostField.content('forwardingNumber', [:forwarding_number]), PostField.content('phoneType', [:phone_type] || 2), PostField.content('subscriberNumber', 'undefined'), PostField.content('remember', 0), PostField.content('_rnr_se', @_rnr_se) ] .merge!({ :post_url => "https://www.google.com/voice/call/connect" }) post(, fields) end |
#cancel_call(options = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/gvoice-ruby/client.rb', line 94 def cancel_call( = {}) fields = [ PostField.content('outgoingNumber', [:outgoing_number] || 'undefined'), PostField.content('forwardingNumber', [:forwarding_number] || 'undefined'), PostField.content('cancelType', 'C2C'), PostField.content('_rnr_se', @_rnr_se) ] .merge!({ :post_url => "https://www.google.com/voice/call/cancel" }) post(, fields) end |
#check(parser = GvoiceRuby::InboxParser.new) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/gvoice-ruby/client.rb', line 39 def check(parser = GvoiceRuby::InboxParser.new) inbox = parser.parse_page(fetch_page) get_unread_counts(inbox) @smss = parser.(inbox['messages']) @voicemails = parser.(inbox['messages']) @all_messages = smss | voicemails @all_messages.sort_by!(&:start_time) end |
#delete_note(options) ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/gvoice-ruby/client.rb', line 165 def delete_note() fields = [ PostField.content('id', [:id]), PostField.content('_rnr_se', @_rnr_se) ] .merge!({ :post_url => 'https://www.google.com/voice/inbox/deletenote'}) post(, fields) end |
#logged_in? ⇒ Boolean
35 36 37 |
# File 'lib/gvoice-ruby/client.rb', line 35 def logged_in? !@curb_instance.nil? end |
#logout ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'lib/gvoice-ruby/client.rb', line 174 def logout if logged_in? @curb_instance.url = "https://www.google.com/voice/account/signout" @curb_instance.perform logger.info "FINISHED LOGOUT #{@curb_instance.url}: HTTP #{@curb_instance.response_code}" @curb_instance = nil end self end |
#mark_as_read(options) ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/gvoice-ruby/client.rb', line 115 def mark_as_read() fields = [ PostField.content('messages', [:id]), PostField.content('read', 1), PostField.content('_rnr_se', @_rnr_se) ] .merge!({ :post_url => 'https://www.google.com/voice/inbox/mark'}) post(, fields) end |
#mark_as_unread(options) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/gvoice-ruby/client.rb', line 125 def mark_as_unread() fields = [ PostField.content('messages', [:id]), PostField.content('read', 0), PostField.content('_rnr_se', @_rnr_se) ] .merge!({ :post_url => 'https://www.google.com/voice/inbox/mark'}) post(, fields) end |
#missed(parser = GvoiceRuby::InboxParser.new) ⇒ Object
49 50 51 52 |
# File 'lib/gvoice-ruby/client.rb', line 49 def missed(parser = GvoiceRuby::InboxParser.new) inbox = parser.parse_page(fetch_page('https://www.google.com/voice/inbox/recent/missed/')) parser.parse_calls(inbox['messages']) end |
#placed(parser = GvoiceRuby::InboxParser.new) ⇒ Object
59 60 61 62 |
# File 'lib/gvoice-ruby/client.rb', line 59 def placed(parser = GvoiceRuby::InboxParser.new) inbox = parser.parse_page(fetch_page('https://www.google.com/voice/inbox/recent/placed/')) parser.parse_calls(inbox['messages']) end |
#received(parser = GvoiceRuby::InboxParser.new) ⇒ Object
54 55 56 57 |
# File 'lib/gvoice-ruby/client.rb', line 54 def received(parser = GvoiceRuby::InboxParser.new) inbox = parser.parse_page(fetch_page('https://www.google.com/voice/inbox/recent/received/')) parser.parse_calls(inbox['messages']) end |
#send_sms(options, show_details = true) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gvoice-ruby/client.rb', line 64 def send_sms(, show_details = true) fields = [ PostField.content('phoneNumber', [:phone_number]), PostField.content('text', [:text]), PostField.content('_rnr_se', @_rnr_se) ] .merge!({ :post_url => "https://www.google.com/voice/sms/send" }) if show_details logger.info "Sending sms..." logger.info " To: #{[:phone_number]}" logger.info " Body: #{[:text]}" logger.info " At: #{Time.now}" end post(, fields) end |
#star(options) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/gvoice-ruby/client.rb', line 135 def star() fields = [ PostField.content('messages', [:id]), PostField.content('star', 1), PostField.content('_rnr_se', @_rnr_se) ] .merge!({ :post_url => 'https://www.google.com/voice/inbox/star'}) post(, fields) end |
#unstar(options) ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/gvoice-ruby/client.rb', line 145 def unstar() fields = [ PostField.content('messages', [:id]), PostField.content('star', 0), PostField.content('_rnr_se', @_rnr_se) ] .merge!({ :post_url => 'https://www.google.com/voice/inbox/star'}) post(, fields) end |