Using DocuSign API and Ruby - ruby

I am getting started with Docusign, and even with Ruby. I am trying to get my head wrapped around something and I need your help.
I am trying in Ruby to create a helper in order to prefill a contract with the information I posses such as the client's information etc. And have that sent to the 2 people who need the contract. I am a little stuck in the steps I need to take in order to get the communication working and grabbing the information I need.
Any help or tips is appreciated.
I have installed the gem for the docusign API, I have the docusign-ruby-client code, I have also created my template, got my integrator key. I am stuck with the next step. How do I actually use in my project all these things together in order to automatically fill in the template with the information from the client ? –
EDITS:
I am unsure on how to use this below in order to get my template, fill it automatically with my client info, and when done, send the pre-filled contract to 2 people.
host = 'https://demo.docusign.net/restapi'
integrator_key = 'e5fdb0cd-a206-4934-91f1-5d00000000'
user_id = 'myemail#gmail.com'
expires_in_seconds = 3600 #1 hour
auth_server = 'account-d.docusign.com'
private_key_filename = '[REQUIRED]'
# STEP 1: Initialize API Client
configuration = DocuSign_eSign::Configuration.new
configuration.host = host
api_client = DocuSign_eSign::ApiClient.new(configuration)
api_client.configure_jwt_authorization_flow(private_key_filename, auth_server, integrator_key, user_id, expires_in_seconds)
# STEP 2: Initialize Authentication API using the API Client
authentication_api = DocuSign_eSign::AuthenticationApi.new(api_client)
# STEP 3: Make the login call
login_options = DocuSign_eSign::LoginOptions.new
login_information = authentication_api.login(login_options)
if !login_information.nil?
login_information.login_accounts.each do |login_account|
if login_account.is_default == "true"
# STEP 4: Extract the user information
base_url = login_account.base_url
account_id = login_account.account_id
puts base_url
puts account_id
# IMPORTANT: Use the base url from the login account to update the api client which will be used in future api calls
base_uri = URI.parse(base_url)
api_client.config.host = "%s://%s/restapi" % [base_uri.scheme, base_uri.host]

Related

Slack API: select conversation members while filtering out bots without n+1

I need to select all members of a conversation who are not bots. It appears the way to do this is to first call conversations.members and then for each member call users.info. Using the slack ruby client, that boils down to this:
client = Slack::Web::Client.new(token: "MY-OAUTH-TOKEN")
# returns an array of user ids
response = client.conversations_members(channel: "#some-channel", limit: 500)
member_ids = response.members
members = member_ids.reject do |member_id|
# returns a https://api.slack.com/types/user object
user = client.users_info(user: member_id)
user["user"]["is_bot"] == true
end
This obviously presents an n+1 problem. I'm wondering if I've overlooked a better API method to call, or an API method argument that could help with this, whether via slack-ruby-client, or just via the vanilla API methods.
Unfortunately, Currently Slack does not have a single API call solution to your problem statement.

How to scrape the data using requests module only in python

I am actually trying to parse a website using the requests module, and extract some text out of it.
Url : https://www.icsi.in/student/Members/MemberSearch.aspx
after hitting the url in the Cp Number text field input : 16803
hit search,
on the bottom you can see some data, I want that data, let's say a name.
I am successfully able to get the data using selenium, but can't able to get it using requests module.
I have tried the requests module giving parameters, sessions, cookies etc.
but nothing worked.
url = "https://www.icsi.in/student/Members/MemberSearch.aspx"
ss = {'dnn$ctr410$MemberSearch$txtCpNumber':'16803',
'__EVENTTARGET':'dnn$ctr410$MemberSearch$btnSearch',
'__VIEWSTATEGENERATOR':'6A295697',
'dnn$ctlHeader$dnnSearch$Search':'SiteRadioButton'}
session = requests.Session()
cookies = session.cookies.get_dict()
for cookie in cookies:
session.cookies.set(cookie['name'], cookie['value'])
response = requests.post(url, data=ss)
print(response)
HTMLTree = html.fromstring(response.content)
name = HTMLTree.xpath('//div[#class="name_head"]//text()')
print(name)
I expect the output of the name of the person.
Anyone out there please help me.
If you don't mind using C# code I would be more than happy to help you otherwise it's a very lengthy process. If you choose that python is the only road you're willing to take then you should try grabbing the encrypted value within C:\User[USERNAME]\Appdata\Local\Google\Chrome\User Data\Default\Cookies You can change the file path accordingly to your OS. You can use SQLite to read and modify the encrypted values.
cookie = Decrypt(Encoding.Default.GetBytes(SQLDatabase1.GetValue(i, "encrypted_value")
if (cookie.Contains(".ASPXANONYMOUS")):
Step1 = cookie + "END"
Step2 = (step1 + ".ASPXANONYMOUS")
The following code above may help you with your journey.

how can I get ALL records from route53?

how can I get ALL records from route53?
referring code snippet here, which seemed to work for someone, however not clear to me: https://github.com/aws/aws-sdk-ruby/issues/620
Trying to get all (I have about ~7000 records) via resource record sets but can't seem to get the pagination to work with list_resource_record_sets. Here's what I have:
route53 = Aws::Route53::Client.new
response = route53.list_resource_record_sets({
start_record_name: fqdn(name),
start_record_type: type,
max_items: 100, # fyi - aws api maximum is 100 so we'll need to page
})
response.last_page?
response = response.next_page until response.last_page?
I verified I'm hooked into right region, I see the record I'm trying to get (so I can delete later) in aws console, but can't seem to get it through the api. I used this: https://github.com/aws/aws-sdk-ruby/issues/620 as a starting point.
Any ideas on what I'm doing wrong? Or is there an easier way, perhaps another method in the api I'm not finding, for me to get just the record I need given the hosted_zone_id, type and name?
The issue you linked is for the Ruby AWS SDK v2, but the latest is v3. It also looks like things may have changed around a bit since 2014, as I'm not seeing the #next_page or #last_page? methods in the v2 API or the v3 API.
Consider using the #next_record_name and #next_record_type from the response when #is_truncated is true. That's more consistent with how other paginations work in the Ruby AWS SDK, such as with DynamoDB scans for example.
Something like the following should work (though I don't have an AWS account with records to test it out):
route53 = Aws::Route53::Client.new
hosted_zone = ? # Required field according to the API docs
next_name = fqdn(name)
next_type = type
loop do
response = route53.list_resource_record_sets(
hosted_zone_id: hosted_zone,
start_record_name: next_name,
start_record_type: next_type,
max_items: 100, # fyi - aws api maximum is 100 so we'll need to page
)
records = response.resource_record_sets
# Break here if you find the record you want
# Also break if we've run out of pages
break unless response.is_truncated
next_name = response.next_record_name
next_type = response.next_record_type
end

django-registration + ajax, user_registered signal randomly fails

I have "successfully" integrated django-registration with ajax in my project.
I'm using the user_registered signal to add additional information to the user upon registering.
Everything works whenever I test it personally. However, when I checked django-admin to see how many users have registered, I noticed that some users were created with only the default fields and does not include the fields created with the signal callback.
Is there a known reason why a django signal would fail?
Here's my user_registered callback:
def user_registered_callback(sender, user, request, **kwargs):
# Create a new instance of Registration form and bind the POST data
form = CustomRegistrationForm(request.POST)
form.full_clean()
# Generate new filename from timestamp and first name
fn = hashlib.md5()
fn.update( str(time.time()) + form.cleaned_data['first_name'] )
filename = fn.hexdigest() + '.jpg'
# Save additional details for the user
u = user
u.first_name = form.cleaned_data['first_name']
u.last_name = form.cleaned_data['last_name']
u.birthdate = form.cleaned_data['birthdate']
u.mobile = form.cleaned_data['mobile']
u.photo = 'photos/' + filename
u.save()
The user_registered signal is a custom signal introduced by django-registration, therefore I assume it would not be triggered if you use Django's original admin site. Also why should it be triggered, since adding a user in the admin is not a user registering himself.
Try registering your handler for post_save of your user class instead:
#receiver(post_save, sender=User)
def user_post_save(sender, instance, **kwargs):
if not instance.pk:
# instance was just created
I accidentally replicated the error and traced through Developer tools what it was.
As it turned out some users were adding strings to first_name that are longer than the maximum I set for that field in the database. However, I wasn't able to add a Form validation for this field that's why it was able to get past my form as valid. Hence, the app was able to create a new user, but when it comes to updating the user_profile it fails making it look like the signal callback didn't run.

Ruby tweetstream stop unexpectedly

I use tweetstream gem to get sample tweets from Twitter Streaming API:
TweetStream.configure do |config|
config.username = 'my_username'
config.password = 'my_password'
config.auth_method = :basic
end
#client = TweetStream::Client.new
#client.sample do |status|
puts "#{status.text}"
end
However, this script will stop printing out tweets after about 100 tweets (the script continues to run). What could be the problem?
The Twitter Search API sets certain arbitrary (from the outside) limits for things, from the docs:
GET statuses/:id/retweeted_by Show user objects of up to 100 members who retweeted the status.
From the gem, the code for the method is:
# Returns a random sample of all public statuses. The default access level
# provides a small proportion of the Firehose. The "Gardenhose" access
# level provides a proportion more suitable for data mining and
# research applications that desire a larger proportion to be statistically
# significant sample.
def sample(query_parameters = {}, &block)
start('statuses/sample', query_parameters, &block)
end
I checked the API docs but don't see an entry for 'statuses/sample', but looking at the one above I'm assuming you've reached 100 of whatever statuses/xxx has been accessed.
Also, correct me if I'm wrong, but I believe Twitter no longer accepts basic auth and you must use an OAuth key. If this is so, then that means you're unauthenticated, and the search API will also limit you in other ways too, see https://dev.twitter.com/docs/rate-limiting
Hope that helps.
Ok, I made a mistake there, I was looking at the search API when I should've been looking at the streaming API (my apologies), but it's possible some of the things I was talking about could be the cause of your problems so I'll leave it up. Twitter definitely has moved away from basic auth, so I'd try resolving that first, see:
https://dev.twitter.com/docs/auth/oauth/faq

Resources