How to delete the attendance check function in Google invitation in Rails? - ruby-on-rails

I'm trying to implement a just notification Google calendar invitation. Currently I'm using Ruby to send a conventional Google Calendar invitation in the service, and it has "yes or no" attendance check button. In order not to attend the meeting, our service customer should indicate their unavailability via the website, but it seems they just clicked no there.
The below is my current code and I think I have to add one or two lines in this code but I'm now sure what that is.
begin
event = {
'summary' => 'Ringle Class',
'description' => 'Ringle Class Notification. Case:' + lesson.course.title,
'start' => {
'dateTime' => lesson.start_time.to_datetime
},
'end' => {
'dateTime' => (lesson.start_time + 1.hour ).to_datetime
},
'attendees' => [
{'email' => lesson.student.email},{'email' => 'xx#xx.com'}
],
}
results = GOOGLE_CAL_CLIENT.execute!(
:api_method => GOOGLE_CAL_API.events.insert,
:parameters => {
:calendarId => GOOGLE_CAL_ID,
'sendNotifications' => true,
'locked' => true,
},
:body_object => event)
lesson.ginv_student = true
lesson.save
$google_invi_log.debug "Sent to the student#{lesson.id}"
rescue
$google_invi_log.debug "Not sent to the student #{lesson.id}"
end
Please share with me any idea you have (:!!
Best

Related

How to create a Issue with custom "Reporter" from a JIRA Rails gem

Acccording to https://github.com/sumoheavy/jira-ruby rails gem I have to setup a valid jira user and api password to allow me access Jira api.
I can create issue according to the follow code but when I see the record logs or even in the Jira page the Reporter title goes with my username. I need to create the Issue username "reporter" from my html input form which I don't know what my user will type...
So how can I create an Issue with custom usernames user Rails Jira gem?
According to their test suite:
JIRA::Resource::Issue.new(client, attrs: {
'id' => '123',
'fields' => {
'reporter' => { 'foo' => 'bar' },
'assignee' => { 'foo' => 'bar' },
'project' => { 'foo' => 'bar' },
'priority' => { 'foo' => 'bar' },
'issuetype' => { 'foo' => 'bar' },
'status' => { 'foo' => 'bar' },
'components' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }],
'versions' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }],
'comment' => { 'comments' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] },
'attachment' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }],
'worklog' => { 'worklogs' => [{ 'foo' => 'bar' }, { 'baz' => 'flum' }] }
}
})
end
Which means you should be able to write:
issue = client.Issue.build
issue.save({"fields"=>{"reporter"=> {"username" => "reporter"},"summary" => {"Crazy froggy"}}
I'm guessing as to "username" being the appropriate key here - but if they're calling this in a spec, then you should be able to call it in your code.
Now the problem may be that "reporter" isn't a valid user within Jira - because their spec tests:
it 'has the correct relationships' do
expect(subject).to have_one(:reporter, JIRA::Resource::User)
expect(subject.reporter.foo).to eq('bar')
The expect(subject).to have_one(:reporter, JIRA::Resource::User) line suggests that the 'reporter' value has to be a valid instance of JIRA::Resource::User which tells me that you cannot set this field to whatever you want. I think that JIRA charges based on how many accounts you have for your JIRA instance? So each User would be a separate license.
I'm doing a lot of guesswork here - but I think this means you need to pay to license the 'reporter' User within JIRA, and then you could set it for all these issues.

Rails + Google Calendar API events not created

I created rails web app. When user make some actions, my app must create new event in my Google Calendar. For my task I choose server-to-server authorization.
I wrote next ruby code:
client = Google::APIClient.new({:application_name => "Rails calendar",
:application_version => "1.0"})
keypath = Rails.root.join('config','google_secrets.p12').to_s
key = Google::APIClient::PKCS12.load_key(keypath, "notasecret")
# generate request body for authorization
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/auth/calendar',
:issuer => '***',
:signing_key => key).tap{ |auth| auth.fetch_access_token! }
api_method = client.discovered_api('calendar','v3').events.insert
#meeting_data = {
guests: [{email: '***#gmail.com'}, {email: '***#gmail.com'}],
start_time: "2016-08-10T19:00:00+03:00",
end_time: "2016-08-10T20:00:00+03:00",
topic: "Test meeting",
messages_thread_id: 2
}
event = {
summary: #meeting_data[:topic],
start: {
dateTime: #meeting_data[:start_time],
time_zone: 'Asia/Jerusalem'
},
end: {
dateTime: #meeting_data[:end_time],
time_zone: 'Asia/Jerusalem'
},
attendees: #meeting_data[:guests],
visibility: 'private',
reminders: {
useDefault: true,
}
}
result = client.execute(:api_method => api_method,
:parameters => {calendarId: 'primary'},
:body => JSON.dump(event),
:headers => {'Content-Type' => 'application/json'})
puts result.data.as_json
But when i try to use that code and server return me result as JSON, if I go on url of "created" event, google show me message that event does not exist.
{"kind"=>"calendar#event", "etag"=>"***", "id"=>"***", "status"=>"confirmed", "htmlLink"=>"https://www.google.com/calendar/event?eid=***", "created"=>"2016-08-04T11:54:46.000Z", "updated"=>"2016-08-04T11:54:46.327Z", "summary"=>"Test meeting", "creator"=>{"email"=>"***", "self"=>true}, "organizer"=>{"email"=>"***", "self"=>true}, "start"=>{"dateTime"=>"2016-08-10T16:00:00Z", "timeZone"=>"Asia/Jerusalem"}, "end"=>{"dateTime"=>"2016-08-10T17:00:00Z", "timeZone"=>"Asia/Jerusalem"}, "visibility"=>"private", "iCalUID"=>"***", "sequence"=>0, "attendees"=>[{"email"=>"***#gmail.com", "displayName"=>"***", "responseStatus"=>"needsAction"}, {"email"=>"***#gmail.com", "displayName"=>"***", "responseStatus"=>"needsAction"}], "reminders"=>{"useDefault"=>true}}
I faced with same problem. Needed give write rules to "client_email" for calendar.
You use organization calendar. Thats why only organization admin can do it.

How to resolve "Insufficient Permission" error in Google Calendar API for Ruby?

I'm trying to use Google Calendar API for Ruby and this is code that I took from the google console site. But when I tried to run this code, I got this error.
......rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/google-api-client-0.8.6/lib/google/api_client.rb:662:in `block (2 levels) in execute!': Insufficient Permission (Google::APIClient::ClientError)
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
require 'google/api_client/auth/storage'
require 'google/api_client/auth/storages/file_store'
require 'fileutils'
APPLICATION_NAME = 'Calendar API Quickstart'
CLIENT_SECRETS_PATH = 'client_secret.json'
CREDENTIALS_PATH = File.join(Dir.home, '.credentials',
"calendar-api-quickstart.json")
#SCOPE = 'https://www.googleapis.com/auth/calendar.readonly'
SCOPE = 'https://www.googleapis.com/auth/calendar'
def authorize
FileUtils.mkdir_p(File.dirname(CREDENTIALS_PATH))
file_store = Google::APIClient::FileStore.new(CREDENTIALS_PATH)
storage = Google::APIClient::Storage.new(file_store)
auth = storage.authorize
if auth.nil? || (auth.expired? && auth.refresh_token.nil?)
app_info = Google::APIClient::ClientSecrets.load(CLIENT_SECRETS_PATH)
flow = Google::APIClient::InstalledAppFlow.new({
:client_id => app_info.client_id,
# :redirect_uri => 'http://localhost:3000/auth/google_oauth2/callback',
:client_secret => app_info.client_secret,
:scope => SCOPE})
auth = flow.authorize(storage)
puts "Credentials saved to #{CREDENTIALS_PATH}" unless auth.nil?
end
auth
end
# Initialize the API
client = Google::APIClient.new(:application_name => APPLICATION_NAME)
calendar_api = client.discovered_api('calendar', 'v3')
client.authorization = authorize
=begin
# Fetch the next 10 events for the user
results = client.execute!(
:api_method => calendar_api.events.list,
:parameters => {
:calendarId => 'primary',
:maxResults => 10,
:singleEvents => true,
:orderBy => 'startTime',
:timeMin => Time.now.iso8601 })
puts "Upcoming events:"
puts "No upcoming events found" if results.data.items.empty?
results.data.items.each do |event|
start = event.start.date || event.start.date_time
puts "- #{event.summary} (#{start})"
puts "- #{event.updated} (#{start})"
# puts "- #{event.accessRole} (#{start})"
##여기에 뭔가 생기는군
end
=end
event = {
'summary' => 'Google I/O 2015',
'location' => '800 Howard St., San Francisco, CA 94103',
'description' => 'A chance to hear more about Google\'s developer products.',
'start' => {
'dateTime' => '2015-05-28T09:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
},
'end' => {
'dateTime' => '2015-05-28T17:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
},
'recurrence' => [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees' => [
{'email' => 'lpage#example.com'},
{'email' => 'sbrin#example.com'},
],
'reminders' => {
'useDefault' => false,
'overrides' => [
{'method' => 'email', 'minutes' => 24 * 60},
{'method' => 'sms', 'minutes' => 10},
],
},
}
results = client.execute!(
:api_method => calendar_api.events.insert,
:parameters => {
:calendarId => 'primary'},
:body_object => event)
event = results.data
puts "Event created: #{event.htmlLink}"
I copied the functioning part from the console site here. How can I allow the permission to use Calendar application?
For the basic read-only app, I was able to run the application because I have Calendar application enabled in the console setting but don't know how to proceed the next step. Please let me know how to solve this issue :)
I was in trouble same to you. You should change two points below:
Your application name is aimed to draw quick sample data by API. It is suitable to set your own application name. The name is one you registered in Google developer console.
You should change credentials path to your own. The path you wrote is only for quick start sample.
{File.join(Dir.home, '.credentials',"calendar-api-quickstart.json"")} >>>
{File.join(Dir.home, '.credentials',"client_secret.json")}

Invalid authorization name/value {x-li-auth-token}/{NAME_SEARCH:tdLy}

Im working on LinkedIn invitation API but I can't send the invitation to user, using people id from search result
Seached people result
**
"{\"people\":{\"total\":2,\"all\":[{\"api_standard_profile_request\":{\"headers\":{\"total\":1,\"all\":[{\"name\":\"x-li-auth-token\",\"value\":\"NAME_SEARCH:tdLy\"}]},\"url\":\"http://api.linkedin.com/v1/people/tp2Z82Xa_I\"},\"first_name\":\"Dev\",\"id\":\"tp2Z8sad2Xa_I\",\"last_name\":\"ruby\"},{\"api_standard_profile_request\":{\"headers\":{\"total\":1,\"all\":[{\"name\":\"x-li-auth-token\",\"value\":\"NAME_SEARCH:ZbY6\"}]},\"url\":\"http://api.linkedin.com/v1/people/TyaEtFbxzL\"},\"first_name\":\"dev\",\"id\":\"TyaEtFbsdsaxzL\",\"last_name\":\"ruby\"}]}}"**
And the invite methods following this
def send_invitation(options)
path = "/people/~/mailbox"
message = {
"recipients" => {
"values" => [
{
"person" => {
"_path" => "/people/id=#{options[:email]}",
"first-name" => options[:first_name],
"last-name" => options[:last_name]
}
}]
},
"subject" => "Invitation to connect.",
"body" => options[:body],
"item-content" => {
"invitation-request" => {
"connect-type" => "friend",
"authorization" => {"name" => "x-li-auth-token","value" => "NAME_SEARCH:tdLy"}
}
}
}
post(path, MultiJson.dump(message), "Content-Type" => "application/json")
end
So I am getting this error when I call client.send_invitation(options):
LinkedIn::Errors::GeneralError: (400): Invalid authorization name/value {x-li-auth-token}/{NAME_SEARCH:tdLy}
Working Fine
The name should be NAME_SEARCH and the value should be tdLy instead of what i have asked above. i have to split the value out of the oauth headers.
"authorization" => {:"name" => 'NAME_SEARCH',:"value" => 'tdLy'}

How to get CPC from Google Adwords Traffic Estimator Service in Ruby on Rails

I've been pouring over the google adwords api docs and I can't figure out how to format the selector to retrieve CPC information. I am using the google-adwords-api gem. Below is the method I'm working on inside my Adwords api module.
def self.traffic_estimator_service keyword
if !#adwords #If not already authenticated, do it first
Adwords.authenticate()
end
traffic_estimator_service = #adwords.service(:TrafficEstimatorService, API_VERSION)
selector = {
:xsi_type => 'KeywordEstimateRequest',
:match_type => 'EXACT',
:keyword => keyword
}
data = traffic_estimator_service.get(selector)
puts '---------------------------------'
puts data.inspect
puts '---------------------------------'
end
Of course I never get to the data2.inspect line because of the api errors. ie:
AdsCommon::Errors::UnexpectedParametersError (AdsCommon::Errors::UnexpectedParametersError: [:match_type]):
I've moved things around and tried multiple things inside the selector hash. Can someone give me an example of what this selector hash should look like?
selector = {
:campaign_estimate_requests => [
{
:xsi_type => 'CampaignEstimateRequest',
:ad_group_estimate_requests => {
:xsi_type => 'AdGroupEstimateRequest',
:keyword_estimate_requests => [
{
:max_cpc => {
:xsi_type => 'Money',
:micro_amount => 1_000_000
},
:xsi_type => 'KeywordEstimateRequest',
:keyword => {
:xsi_type => 'Keyword',
:text => keyword,
:match_type => 'EXACT'
}
}
]
}
}
]
}

Resources